ORA-01747: user.table.column、table.column 或 java 中的列规范无效
ORA-01747: invalid user.table.column, table.column, or column specification in java
我收到这个错误-
ORA-01747: 无效 user.table.column、table.column 或列规范
这是我的代码块-
private void updateAttendance(){
MyQuery mq=new MyQuery();
Connection con=mq.getConnection();
Statement st;
ResultSet rs;
try{
st=con.createStatement();
rs=st.executeQuery("Select STU_ID FROM STUDENT WHERE NAME='"+cmbName.getSelectedItem()+"'");
if(rs.next()){
//System.out.println("getting student name");
int id=rs.getInt("STU_ID");
System.out.println(id);
String sql="UPDATE STUDENT SET CURRENT_DATE='"+lblTime.getText()+"',SUBJECT='"+cmbSub.getSelectedItem()+"',ATTENDANCE=";
if(rdbtnPresent.isSelected())
sql+= "'"+Atdnc[0]+"',";
else
sql+= "'"+Atdnc[1]+"'";
sql+="WHERE STU_ID='"+id+"'";
st.executeUpdate(sql);
//cmbName.removeAllItems();
}
}catch(SQLException ex){
Logger.getLogger(Student.class.getName()).log(Level.SEVERE, null, ex);
}
}
当我执行此查询时(UPDATE STUDENT SET CURRENT_DATE='27TH MAY',SUBJECT='CRYPTOGRAPHY',ATTENDANCE='ABSENT' WHERE STU_ID='40 ';) 在 oracle 11g 中它工作正常......但在 eclipse returns 错误中相同 sql。
你的问题应该在这里:
if (rdbtnPresent.isSelected())
sql+= "'"+Atdnc[0]+"',"; // --> this should be "'" as there is no more field
else
sql+= "'"+Atdnc[1]+"'";
sql+="WHERE STU_ID='"+id+"'"; // --> this should start with a space sql+=" WHERE..
所以你有 2 个问题:
- 如果
rdbtnPresent.isSelected()
return true
,这里有一个逗号无关
- 你的
WHERE
前没有space
NB:
考虑使用 PrepareStatement
来避免此类问题,避免必须转义您的值并避免 SQL 注入攻击。
我收到这个错误- ORA-01747: 无效 user.table.column、table.column 或列规范
这是我的代码块-
private void updateAttendance(){
MyQuery mq=new MyQuery();
Connection con=mq.getConnection();
Statement st;
ResultSet rs;
try{
st=con.createStatement();
rs=st.executeQuery("Select STU_ID FROM STUDENT WHERE NAME='"+cmbName.getSelectedItem()+"'");
if(rs.next()){
//System.out.println("getting student name");
int id=rs.getInt("STU_ID");
System.out.println(id);
String sql="UPDATE STUDENT SET CURRENT_DATE='"+lblTime.getText()+"',SUBJECT='"+cmbSub.getSelectedItem()+"',ATTENDANCE=";
if(rdbtnPresent.isSelected())
sql+= "'"+Atdnc[0]+"',";
else
sql+= "'"+Atdnc[1]+"'";
sql+="WHERE STU_ID='"+id+"'";
st.executeUpdate(sql);
//cmbName.removeAllItems();
}
}catch(SQLException ex){
Logger.getLogger(Student.class.getName()).log(Level.SEVERE, null, ex);
}
}
当我执行此查询时(UPDATE STUDENT SET CURRENT_DATE='27TH MAY',SUBJECT='CRYPTOGRAPHY',ATTENDANCE='ABSENT' WHERE STU_ID='40 ';) 在 oracle 11g 中它工作正常......但在 eclipse returns 错误中相同 sql。
你的问题应该在这里:
if (rdbtnPresent.isSelected())
sql+= "'"+Atdnc[0]+"',"; // --> this should be "'" as there is no more field
else
sql+= "'"+Atdnc[1]+"'";
sql+="WHERE STU_ID='"+id+"'"; // --> this should start with a space sql+=" WHERE..
所以你有 2 个问题:
- 如果
rdbtnPresent.isSelected()
returntrue
,这里有一个逗号无关 - 你的
WHERE
前没有space
NB:
考虑使用 PrepareStatement
来避免此类问题,避免必须转义您的值并避免 SQL 注入攻击。