Importing csv file in mysql database -


I have a CSV file with 8 columns. When I am importing the CSV file to a MySQL database, it is ignoring the second column and changing the data from the left to the other columns, please help.

I think the problem is with CSV. Some CSV files have been successfully uploaded as file, how can I fix it?

My query is to store this CSV file in the database:

  Load data INFILE '$ file_name' in '$ file_name' defined in the tablet import field '| ' LINES TERMINATED BY '\ N' IGNORE 1 LINES (@ srno, @custom_name, @ date, @ mobileo, @ city, @ state, @ type, @tailor) SET customer_name = @ customer_name, date = @ date, mobno = @ mobno , City = @ city, state = @ state, type = @ type, tellyer = @tailor, datetime = '$ datetime'    

This code worked for me to check it from the local database

  package Example_Import; Import java.sql *; Import java.text.ParseException; Import java.text.SimpleDateFormat; Import java.io * *; Import java.lang.String; Import java.util.Scanner; Public class examples {// import mysql-connector-java-5.1.32.jar //http://www.tutorialspoint.com/jdbc/jdbc-create-tables.htm Private Static String JDBC_URL = "jdbc: mysql: / / Local Host: 3306 / Sakila "; Private String String USER = "root"; Private static string PASSWORD = "2004"; Public static zero master (string [] args throws IOException {connection myConnection = null; Statement statement = null; Preparation ready prepared situation = null; Try {// connect to database myconnection = DriverManager.getConnection (JDBC_URL, USER, password); System.out.println ("Connect to database"); // Creating table in connected // database system. Out.println ("Create a table in the given database ..."); Statement = myConnection.createStatement (); "+" Table registration "+" (ID integer tap, "+" previous VARAR (25), "+" first VAARAAR (25), "+" balance flot, "+" credit float, "+" DATE DATE, "+" Rating CHAR, "+" primary key (id)) "; Statement.executeUpdate (SQL); System.out.println ("Created the table in the given database ..."); Statement.close (); // Close Statement / A Ready statement string insertTableSQL = "INSERT inside registration" (ID, last, first, balance, credit, date, rating) values ​​"+" (?,?,?,?,?, ??,?) "; Replacement = myConnection.prepareStatement (insertTableSQL); // Recovering from the CSV file // BufferedReader Reader = New BufferedReader (New FileReader (" SAMPLE.csv ")) to open a file input stream; string Line = faucet; // line csv scanner scanner = read from null; // scan line simplified format date = new simpledeferms ("Mm / dd / yay"); reader.readLine (); // leaves the file line to read the first line // from the line and upload the information for the database while ((line = reader.readline )! = Null) {scanner = new scanner (line); scanner.useDelimiter (","); while (scanner.hasNext ()) {readyStatement.setInt (1, integer.parissant (scanner.nxt)); ReadyStatement.setString (2, scanner.next ()); ReadyStatement.setString (3, scanner.next ()); ReadyStatement.setFloat (4, Float. PRSFlot (scanner.NXT)); ReadyStatement.setFloat (5, float.prsflot (scanner.xt ()); Try {java.util.Date d; D = date.parse (scanner.next ()); ReadyStatement.setDate (6, new java sql.Date (d.getTime ())); } Hold (ParseException e) {e.printStackTrace (); } Preparedness Setstring (7, scanner.xt ()); } Preparedness ExecuteUpdate (); } Prepared position Close (); System.out.println ("Data Imported"); Reader.close (); // close the CSV reader} hold (eclipse e) {e.printStackTrace (); } Try {// closing connection at the end {if (comment! = Null) myConnection.close (); } Hold (with SQLException) {} // Try nothing {if (myConnection! = Tap) myConnection.close (); } Grip (from eclipsection) {se.printStackTrace (); } System.out.println ("connection closed"); }}}    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -