snajalm
asked on
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "80" at line 1, column 1100.
I get the exception in the question title when I try to insert like the following! Any idea what this could mean??!
String insertString = "insert into queries (data_id, query, "
+ "query_name, query_file_name, status) values(" + currentDataID + ", '" + params[1] + "', '" + params[2] + "', '" + params[3] + "', '" + params[4] + "')";
try {
Statement stmt = dbconn.createStatement();
stmt.execute(insertString, Statement.RETURN_GENERATED_KEYS);
ResultSet rs = stmt.getGeneratedKeys();
if (rs != null && rs.next()){
currentDataID = (int) rs.getLong(1);
}
} catch (SQLException ex) {
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
Just print the sql query and paste here so we can help you quickly whats wrong with the query.
String insertString = "insert into queries (data_id, query, "
+ "query_name, query_file_name, status) values(" + currentDataID + ", '" + params[1] + "', '" + params[2] + "', '" + params[3] + "', '" + params[4] + "')";
System.out.println(insertS tring );
try {
Statement stmt = dbconn.createStatement();
stmt.execute(insertString, Statement.RETURN_GENERATED _KEYS);
ResultSet rs = stmt.getGeneratedKeys();
if (rs != null && rs.next()){
currentDataID = (int) rs.getLong(1);
}
} catch (SQLException ex) {
}
Thank you
Just print the sql query and paste here so we can help you quickly whats wrong with the query.
String insertString = "insert into queries (data_id, query, "
+ "query_name, query_file_name, status) values(" + currentDataID + ", '" + params[1] + "', '" + params[2] + "', '" + params[3] + "', '" + params[4] + "')";
System.out.println(insertS
try {
Statement stmt = dbconn.createStatement();
stmt.execute(insertString,
ResultSet rs = stmt.getGeneratedKeys();
if (rs != null && rs.next()){
currentDataID = (int) rs.getLong(1);
}
} catch (SQLException ex) {
}
Thank you
ASKER
I managed to use PreparedStatement in my code and got rid of this issue, however, I'm getting a new exception which is
Even though my field is set up to be LONG VARCHAR I get this error with an entry of 1200 characters.
java.sql.SQLDataException: A truncation error was encountered trying to shrink VARCHAR 'SELECT s . . .
Even though my field is set up to be LONG VARCHAR I get this error with an entry of 1200 characters.
It is trying to insert the values which is more than the lenght of varchar field.
can you try reducing the length of the fields retrieved either in the query or just increase the field length to hold the same.
can you try reducing the length of the fields retrieved either in the query or just increase the field length to hold the same.
You can test Rinil's hypothesis by putting a temporary substring(0, 32) (or some such) on the string params
ASKER
Thanks guys!
ASKER