Dear Forums,
I have a doubt i want to import data from Excel sheet to Mysql database i have done the vice versa its working fine....When i have done it by exporting data from excel to database its not accepting multiple records its taking only one record.........Can anyone help me out in this.....Any solution would be appreciable...........Thanks in advance........the below is my code.........
import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import java.sql.ResultSet; import java.sql.SQLException; @SuppressWarnings("unused") public class automateImport { public static void main(String[] args) { DBase db = new DBase(); Connection conn = db.connect( "jdbc:mysql://localhost:3306/sample","root","root"); // db.importData(conn,args[0]); db.importData(conn, "/home/venugopal/data.xls"); } } class DBase { public DBase() { } public Connection connect(String db_connect_str, String db_userid, String db_password) { Connection conn; try { Class.forName( "com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection(db_connect_str, db_userid, db_password); } catch(Exception e) { e.printStackTrace(); conn = null; } return conn; } public void importData(Connection conn,String filename) { Statement stmt; String query; try { stmt = conn.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); query = "LOAD DATA INFILE '/home/venugopal/data.xls' INTO TABLE employee (id,name,address,contactNo,email);"; stmt.executeUpdate(query); } catch(Exception e) { e.printStackTrace(); stmt = null; } } };
Regards,
Venu