Jeetesh Nataraj Jeetesh Nataraj - 1 year ago 148
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 Source

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+"')";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download