Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static String getCreateTable1(Connection con, String tablename) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Statement stmt = con.createStatement();
- String createtable = "CREATE TABLE " + tablename
- + " ( text VARCHAR(255), price INT , day VARCHAR(255), litres FLOAT )";
- System.out.println("Create a new table in the database");
- stmt.executeUpdate(createtable);
- } catch (Exception e) {
- System.out.println(((SQLException) e).getSQLState());
- System.out.println(e.getMessage());
- e.printStackTrace();
- }
- return null;
- }
- private static String importData(Connection con, File txtFile,
- String tablename) {
- try {
- Statement stmt;
- stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
- ResultSet.CONCUR_UPDATABLE);
- String path = txtFile.getAbsolutePath();
- String importingdata = "LOAD DATA INFILE '"
- + path.replace('\', '/')
- + "' INTO TABLE " + tablename
- + " FIELDS TERMINATED BY 't'";
- System.out.println("fill the table");
- stmt.executeUpdate(importingdata);
- } catch (Exception e) {
- System.out.println(((SQLException) e).getSQLState());
- System.out.println(e.getMessage());
- e.printStackTrace();
- }
- return null;
- }
- LOAD DATA INFILE 'myfile.txt'
- INTO TABLE tablename
- FIELDS TERMINATED BY 't'
- (COL1, @litres, COL3, ...) -- Note the @ in front of the float column
- SET litres = REPLACE(@litres, ',', '.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement