This is the output im recieving:
INSERT INTO [ J] VALUES ([J1, Sorter, Paris)
INSERT INTO [ J] VALUES (J2, Punch, Rome)
INSERT INTO [ J] VALUES (J3, Reader, Athens)
INSERT INTO [ J] VALUES (J4, Console, Athens)
INSERT INTO [ J] VALUES (J5, Collator, London)
INSERT INTO [ J] VALUES (J6, Termninal, Oslo)
INSERT INTO [ J] VALUES (J7, Tape, London])
As you can see i have a [ at the beginning and a ] at the end and i don't know what is causing it? how can i remove it? i have tried regex it with .replace("[ ]",""); where i belive the problem is occuring but to no avail.
Code for inserting:
if (state == 3||!tableLineScanner.hasNextLine()){
try{
Class.forName("org.sqlite.JDBC");
Connection conn = null;
conn = DriverManager.getConnection("jdbc:sqlite:test.db");
//TODO Input values goes here
tableName =""+tableNames;
Statement stmt = conn.createStatement();
String query = tableValues + "";
ResultSet rs = stmt.executeQuery("SELECT * FROM "+ tableName);
ResultSetMetaData rsmd = rs.getMetaData();
query.replaceAll("[ ]","");
tableName =""+tableNames;
tableName.replaceAll("[ ]","");
String[] splittedOutput = query.split(", ");
int valuesOnLine = rsmd.getColumnCount();
for (int i = 0; i < splittedOutput.length; i++) {
if (i % valuesOnLine == 0) {
System.out.print("INSERT INTO " + tableName + " VALUES (");
}
System.out.print(splittedOutput[i]);
if (i % valuesOnLine == valuesOnLine - 1) {
System.out.println(")");
} else {
System.out.print(", ");
}
}
tableNames.clear();
tableValues.clear();
tableFields.clear();
}
catch (SQLException ex){
System.out.println("SQLException: " + ex.getMessage());
System.out.println("VendorError: " + ex.getErrorCode());
}
catch (ClassNotFoundException e){
e.printStackTrace();
}
}