Parsing data into tables

后端 未结 2 1300

I have created a connection with Mysql and java program via jdbc. Now I want to populate the tables in the mysql database. How do I parse the data into the tables from the java

相关标签:
2条回答
  • 2021-01-28 11:47

    You can use the LOAD DATA INFILE SQL command.

    0 讨论(0)
  • 2021-01-28 11:50

    An easy solution: read a single line an use the content as a part of an SQL INSERT command:

    List<String> lines = getAllLinesFromFile(file);
    for (String line: lines) {
      String query = "INSERT INTO \"TABLE\" (COL1, ..., COL9) VALUES("+line+");";
      stmt.executeUpdate(query);
    }
    

    Replace TABLE with your actual tablename and COL1, ..., COL9 with an enumeration of your column names. There may be solutions with a better database performance (like using prepared statements) but the algorithm is easy and sufficient to get some data into the database.

    0 讨论(0)
提交回复
热议问题