Bug #70190 How can import data from excel sheet and store it in my sql
Submitted: 30 Aug 2013 7:26 Modified: 2 Sep 2013 11:48
Reporter: aravind reddy Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL for Windows: MySQL for Excel Severity:S3 (Non-critical)
Version: OS:Windows
Assigned to: CPU Architecture:Any

[30 Aug 2013 7:26] aravind reddy
Description:
How can import data from excel sheet and store it in my sql

How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.lang.*;
 
@SuppressWarnings("unused")
public class automateImport
{
    public static void main(String[] args) 
    {
        DBase db = new DBase();
        Connection conn = db.connect(
    "jdbc:mysql://localhost:3306/vema","root","aravind");
//        db.importData(conn,args[0]);
        db.importData(conn, "d:/student.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 local INFILE 'D:/student.xls' ignore INTO TABLE student fields terminated by ',' optionally enclosed by ',' Lines terminated by '\r\n'; 
            stmt.executeUpdate(query);
 
        }
        catch(Exception e)
        {
			//System.out.println(e);
            e.printStackTrace();
			
            //stmt = null;
        }
    }
};
[30 Aug 2013 7:27] aravind reddy
row 2 was truncated it contained more data than there were input columns
[2 Sep 2013 11:48] MySQL Verification Team
We're sorry, but the bug system is not the appropriate forum for asking help on using MySQL products. Your problem is not the result of a bug.

Support on using our products is available both free in our forums at http://forums.mysql.com/ and for a reasonable fee direct from our skilled support engineers at http://www.mysql.com/support/

Thank you for your interest in MySQL.