Results 1 to 3 of 3
  1. #1
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    285
    Rep Power
    3

    Exclamation JFileChooser making trouble while passing the file path

    Good Morning Sir!

    i try to select the .csv file and pass it to the "mysql query" by the fallowing code

    Java Code:
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
               Statement stmt;
               String query;
         try
                    {
                         Class.forName("com.mysql.jdbc.Driver");
                         Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/payslip", "root", "root");
                         stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
            JFileChooser file_chooser = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("csv", "csv");
            file_chooser.setFileFilter(filter);
            int users_value = file_chooser.showOpenDialog(file_chooser);
            if (users_value == JFileChooser.APPROVE_OPTION) {
                File filee = file_chooser.getSelectedFile();
                //FileInputStream fin = new FileInputStream(filee);
                String pathone=filee.getPath();
                         String Pathtwo="C:/Users/read/Desktop/data.csv";
                         query = "LOAD DATA INFILE '"+filee+"' INTO TABLE aprvlev FIELDS TERMINATED BY ',' (ApprovalDate,ApprovalReason) ";
                         stmt.executeUpdate(query);
                         JOptionPane.showMessageDialog(null, "Sceeceefully Stored From Excell TO MySQL");
            }
                    }
                    catch(Exception r)
                    {
                        JOptionPane.showMessageDialog(null, r);
                        System.out.println(r);
                    }
    }
    If i pass the path as String it working well

    Java Code:
     String Pathtwo="C:/Users/read/Desktop/data.csv";
    query = "LOAD DATA INFILE '"+Pathtwo+"' INTO TABLE aprvlev FIELDS TERMINATED BY ',' (ApprovalDate,ApprovalReason) ";
    But!

    if i pass file or file path by filechooser


    Java Code:
     File filee = file_chooser.getSelectedFile();
     query = "LOAD DATA INFILE '"+filee+"' INTO TABLE aprvlev FIELDS TERMINATED BY ',' (ApprovalDate,ApprovalReason) ";
    or

    Java Code:
    String pathone=filee.getPath();
    query = "LOAD DATA INFILE '"+pathone+"' INTO TABLE aprvlev FIELDS TERMINATED BY ',' (ApprovalDate,ApprovalReason) ";
    it giving the fallowing error sir,

    Java Code:
    java.sql.SQLException: File 'C:\ProgramData\MySQL\MySQL Server 5.5\Data\UserseadDesktopdata.csv' not found (Errcode: 22)
    What i have to do, can you guide me please..,
    Thank you sir..,

  2. #2
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    285
    Rep Power
    3

    Default Re: JFileChooser making trouble while passing the file path

    when i print the path by System.Out.Println();, it give the right path sir.

    String pathone=filee.getPath();
    System.Out.Println(pathone);

    But while specified only it making problem..,

    What i have to change in my coding please..,
    thank you sir..,
    Last edited by raj.mscking@gmail.com; 06-07-2012 at 04:51 AM.

  3. #3
    raj.mscking@gmail.com's Avatar
    raj.mscking@gmail.com is offline Senior Member
    Join Date
    Jan 2012
    Location
    TamilNadu
    Posts
    285
    Rep Power
    3

    Default Re: JFileChooser making trouble while passing the file path

    Good Morning Sir!
    For the past one day, i tried to find out the solution in many ways,
    But it making the same problem..,
    Can You please Guide me sir..,
    Thank you..,

Similar Threads

  1. Replies: 11
    Last Post: 05-11-2012, 02:19 PM
  2. Replies: 4
    Last Post: 03-21-2011, 04:45 AM
  3. Trouble drawing image from file picked by JFileChooser
    By I = new NewToJava() in forum New To Java
    Replies: 6
    Last Post: 12-26-2010, 03:54 PM
  4. trouble with JFileChooser
    By grcunning in forum AWT / Swing
    Replies: 3
    Last Post: 09-04-2010, 08:34 PM
  5. Replies: 8
    Last Post: 01-21-2010, 07:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •