用户缺少权限或找不到对象.. 使用 UPDATE 语句
User lacks privilege or object not found.. with UPDATE statement
我正在尝试通过这种方式在 UPDATE 语句中插入值。我收到一个错误:
SQLSyntaxErrorException:User Lacks Privilage or object not found: intOne in statement.......
代码:
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");
}
}
查询字符串中intOne的使用...可否?
如果可以,那为什么我会得到异常?
您的 intOne
仅存在于您的 java 代码中。数据库不知道它是什么。您需要为其分配 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");
}
}
我正在尝试通过这种方式在 UPDATE 语句中插入值。我收到一个错误:
SQLSyntaxErrorException:User Lacks Privilage or object not found: intOne in statement.......
代码:
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");
}
}
查询字符串中intOne的使用...可否?
如果可以,那为什么我会得到异常?
您的 intOne
仅存在于您的 java 代码中。数据库不知道它是什么。您需要为其分配 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");
}
}