Jeetesh Nataraj Jeetesh Nataraj - 3 months ago 10
Java Question

Java and Database Query?

Using Derby as my data base driver and tying to execute SQL query through java,
there was a error that was encounter, when tried to execute this particular query

stmt.executeQuery("insert into " + "TEST " + "values (" + dataTimeRev + ", "
+ dataType + "," + obj + ")" );


Here dataTimeRev, dataType and obj are variables with data.

The error that was stated was like this

java.sql.SQLSyntaxErrorException: VALUES clause must contain at least one element. Empty elements are not allowed.

Answer

if the column data type is VARCHAR you will have to pass the value in qoutes like 'value' for that you should do as below

String query = "insert into TEST values('"+dataTimeRev+"', '"+dataType+"','"+obj+"')";
stmt.executeQuery(query);
Comments