Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By noobplus

Thread: Import to MySQL from a CSV file

  1. #1
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Import to MySQL from a CSV file

    Hi,

    I am trying to write a program that can import the content of a CSV file into a table in MySQL.
    Any good links to tutorials?

    I am using Netbeans...

  2. #2
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: Import to MySQL from a CSV file

    Quote Originally Posted by asai View Post
    Hi,

    I am trying to write a program that can import the content of a CSV file into a table in MySQL.
    Any good links to tutorials?

    I am using Netbeans...
    hi,
    google first result
    Import Data from Txt or CSV files into MYSQL database tables

    regards
    dhilip
    asai likes this.

  3. #3
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Import to MySQL from a CSV file

    Thanks!

  4. #4
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: Import to MySQL from a CSV file

    Quote Originally Posted by asai View Post
    Thanks!
    welcome , click like button

  5. #5
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Import to MySQL from a CSV file

    I have tried this but something isn't right with my code...

    Java Code:
    String filename = textFileName.getText();
    String query = "LOAD DATA INFILE '"+filename+"' INTO TABLE TestTable  FIELDS TERMINATED BY ',' (FirstName,LastName,Location)";
    I have a textfield for input of the filepath.
    I type C:\Temp\Test.csv in this field, but when I run the code I get an exeption:
    Java Code:
    java.sql.SQLException: File '/var/lib/mysql/genealogy/C:Temp	est1.csv' not found (Errcode: 2)
    EDIT: I changed the query to this:
    Java Code:
    String query = "LOAD DATA LOCAL INFILE '"+filename+"' INTO TABLE TestTable  FIELDS TERMINATED BY ',' (FirstName,LastName,Location)";
    But it still do something wrong with the path...
    Last edited by asai; 03-18-2012 at 11:22 AM.

  6. #6
    asai is offline Senior Member
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    115
    Rep Power
    0

    Default Re: Import to MySQL from a CSV file

    Update: I have managed to get it to work, but not 100%...
    If I write the path like this: C:\\Temp\\test.csv it imports the content of the file.

    I would also like to have the first row in the csv file to hold the table columnnames.
    Any suggestions?

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Import to MySQL from a CSV file

    Go to the MySQL documentation and read up on how that command works.
    There may well be options on it.
    This really, really, isn't a Java question.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 04-02-2011, 10:22 AM
  2. How do I import a list file?
    By Codeless in forum New To Java
    Replies: 1
    Last Post: 11-14-2010, 02:36 PM
  3. how to import xfdf file into the pdf file
    By jkrishnanvenkat in forum New To Java
    Replies: 3
    Last Post: 11-09-2009, 02:46 AM
  4. How to import file from same directory?
    By Splat in forum New To Java
    Replies: 5
    Last Post: 10-14-2009, 04:11 AM
  5. how to import war file with tomcat?
    By makpandian in forum NetBeans
    Replies: 0
    Last Post: 12-31-2008, 11:00 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
  •