Im using NetBeans to create a data entry software for a friend.
when I save a data, it create a folder in specified location, and the name of that folder will be different from each other
for example. 1.JPG

it pick the Date,Invoice Number, Subject name, and create the folder. inside that folder to export the fields of the file in a .exel or .txt

and is possible the 2 imported pics to be saved in the some file?

this is the code I use to save/import data into SqLite

   try{
                String sql= "INSERT INTO DataImput (Invoicenumber,Date,SubjectName,VATnumber,Service,Totalamount,Image,Image2) VALUES (?,?,?,?,?,?,?,?)";
                pst=conn.prepareStatement(sql);
                pst.setString(1, txt_in.getText());
                pst.setString(2, txt_date.getText());
                pst.setString(3, txt_sn.getText());
                pst.setString(4, txt_vatnr.getText());
                pst.setString(5, txt_ser.getText());
                pst.setString(6, txt_ta.getText());
                pst.setBytes(7, bill_image);
                pst.setBytes(8, bill_image1);


                pst.execute();
                JOptionPane.showMessageDialog(null, "Data saved");

            }catch (Exception e){
                JOptionPane.showMessageDialog(null, e);



            }finally{
            try{
             rs.close();
             pst.close();                
            }
              catch(Exception e){        
                                }    

            }

Image importer

      JFileChooser chooser = new JFileChooser();
        chooser.showOpenDialog(null);
        File f = chooser.getSelectedFile();
        filename = f.getAbsolutePath();

       image_path1.setText(filename);


       try{

           File image = new File (filename);
           FileInputStream fis = new FileInputStream(filename);

          ByteArrayOutputStream  bos = new ByteArrayOutputStream();

           byte[] buf = new byte[1024];

           for (int readNum; (readNum=fis.read(buf))!=-1; ){

               bos.write(buf,0,readNum);

           }
            bill_image = bos.toByteArray();


       }
       catch(Exception e){
       JOptionPane.showMessageDialog(null, e);
       }


private ImageIcon format = null;

String filename = null;

int s=0;
byte[] bill_image = null;

So can anyone Help me? Im really in need for fast help

this is the importing data section
4.JPG

Dani AI

Generated

For : a simple, reliable flow is to query the SQLite rows and, for each row, create one sanitized folder named from the Date+Invoice+Subject, write a small CSV/TXT with the row fields, and write each image BLOB to a separate file inside that folder. Storing original filenames or MIME types when importing makes the export far simpler; if those were not saved, detect the image type with ImageIO or fall back to a sensible extension.

Steps to implement

  • Run a SELECT for the records to export.
  • Build a folder name such as YYYY-MM-DD_invoice_subject and remove illegal filename chars (\/:*?"<>|) and trim length.
  • Create the folder with Files.createDirectories(path).
  • Stream BLOBs from the ResultSet (use getBinaryStream) and write to disk with Files.copy to avoid loading large BLOBs fully into memory.
  • Write the record data as CSV or a simple text file (quote fields that contain commas). For Excel exports, generate .xlsx with Apache POI and embed images if desired.

Minimal example (concept)

Path dir = Paths.get(baseDir, sanitize(folderName));
Files.createDirectories(dir);

try (InputStream in = rs.getBinaryStream("Image")) {
    if (in != null) Files.copy(in, dir.resolve("image-1.jpg"), StandardCopyOption.REPLACE_EXISTING);
}
try (InputStream in2 = rs.getBinaryStream("Image2")) {
    if (in2 != null) Files.copy(in2, dir.resolve("image-2.jpg"), StandardCopyOption.REPLACE_EXISTING);
}

List<String> csv = Arrays.asList("Invoice,Date,Subject", invoice + "," + date + "," + subject);
Files.write(dir.resolve("data.csv"), csv, StandardCharsets.UTF_8);

Troubleshooting notes

  • Prefer streaming (getBinaryStream) to ResultSet.getBytes for large images to avoid OOM.
  • If original extensions were not stored, use ImageIO.read or inspect magic bytes; otherwise use .bin.
  • Watch permissions, filename length limits, and concurrency if exporting many rows in parallel.
  • For embedding images into spreadsheets, use Apache POI; for simple per-record folders, CSV + image files is easiest.

References: Apache POI quick guide (for Excel image embedding) and the SQLite JDBC driver are practical resources.

(As observed, clarifying the intended output helps pick CSV vs .xlsx; as asked, source is SQLite per .)

Recommended Answers

All 4 Replies

thanks for those, but not in C#
but in Java. I know how to put date and those. just want to create a file by the name and import the data inside.

I'm not sure what you are trying to do?

Are you storing the data in a SQL database, or in files inside a directory???

Im storing those in SqLite
but when export to put those in files inside a directory

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.