I'm trying this way to insert value in UPDATE statement. I'm getting an error:
SQLSyntaxErrorException:User Lacks Privilage or object not found: intOne in statement.......
Code:
private int oneValue(){
PreparedStatement ps= conn.prepareStatement("select col1 from
tableOne ");
ResultSet rs =ps.executeQuery;
while(rs.next){
String str=rs.getString("columnName").toString;
int intOne= Integer.parseInt(str);
}
return intOne;
}
Now :
private void theQuestionHere(int intOne){
this.intOne=intOne;
ps=conn.prepareStatement("update tableOne set col2=? where
col1=intOne);
ps.setBytes(1,"anyByteArray");
int anotherInt=ps.executeUpdate;
if(int>0){
System.out.println("OK");
}
else{
System.out.println("Not OK");
}
}
The use of intOne in the query string... can be or no?
If can, then why am I getting the exception?
Your intOne
only exists in your java code. The database does not know what it is. You need to assign it the PreparedStatement.
private void theQuestionHere(int intOne){
byte[] aByteArray = byte[] {1, 2, 3, 4};
ps=conn.prepareStatement("update tableOne set col2=? where col1=?");
ps.setBytes(1,aByteArray);
ps.setInt(2, intOne);
int anotherInt=ps.executeUpdate;
if(int>0){
System.out.println("OK");
}
else{
System.out.println("Not OK");
}
}