Results 1 to 3 of 3
- 06-07-2012, 03:15 AM #1
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
JFileChooser making trouble while passing the file path
Good Morning Sir!
.gif)
i try to select the .csv file and pass it to the "mysql query" by the fallowing code
If i pass the path as String it working wellJava 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); } }
But!Java Code:String Pathtwo="C:/Users/read/Desktop/data.csv"; query = "LOAD DATA INFILE '"+Pathtwo+"' INTO TABLE aprvlev FIELDS TERMINATED BY ',' (ApprovalDate,ApprovalReason) ";
if i pass file or file path by filechooser
orJava Code:File filee = file_chooser.getSelectedFile(); query = "LOAD DATA INFILE '"+filee+"' INTO TABLE aprvlev FIELDS TERMINATED BY ',' (ApprovalDate,ApprovalReason) ";
it giving the fallowing error sir,Java Code:String pathone=filee.getPath(); query = "LOAD DATA INFILE '"+pathone+"' INTO TABLE aprvlev FIELDS TERMINATED BY ',' (ApprovalDate,ApprovalReason) ";
What i have to do, can you guide me please..,Java Code:java.sql.SQLException: File 'C:\ProgramData\MySQL\MySQL Server 5.5\Data\UserseadDesktopdata.csv' not found (Errcode: 22)
Thank you sir..,
- 06-07-2012, 04:47 AM #2
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
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.
- 06-08-2012, 03:45 AM #3
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 162
- Rep Power
- 2
Similar Threads
-
JFileChooser Multiple selection how to get the canonical path of the each file select
By RichersooN in forum AWT / SwingReplies: 11Last Post: 05-11-2012, 02:19 PM -
Using a JFileChooser to get absolute path of a file
By jetnor in forum AWT / SwingReplies: 4Last Post: 03-21-2011, 04:45 AM -
Trouble drawing image from file picked by JFileChooser
By I = new NewToJava() in forum New To JavaReplies: 6Last Post: 12-26-2010, 03:54 PM -
trouble with JFileChooser
By grcunning in forum AWT / SwingReplies: 3Last Post: 09-04-2010, 08:34 PM -
How to set the path when i Browse Using JFileChooser?
By mlibot in forum New To JavaReplies: 8Last Post: 01-21-2010, 07:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks