Sayantan Chandra Sayantan Chandra - 2 years ago 255
MySQL Question

ORA-01747: invalid user.table.column, table.column, or column specification in java

I am getting this error-
ORA-01747: invalid user.table.column, table.column, or column specification

And this is my block of code-

private void updateAttendance(){
MyQuery mq=new MyQuery();
Connection con=mq.getConnection();
Statement st;
ResultSet rs;
rs=st.executeQuery("Select STU_ID FROM STUDENT WHERE NAME='"+cmbName.getSelectedItem()+"'");
//System.out.println("getting student name");
int id=rs.getInt("STU_ID");
String sql="UPDATE STUDENT SET CURRENT_DATE='"+lblTime.getText()+"',SUBJECT='"+cmbSub.getSelectedItem()+"',ATTENDANCE=";

sql+= "'"+Atdnc[0]+"',";
sql+= "'"+Atdnc[1]+"'";

sql+="WHERE STU_ID='"+id+"'";

}catch(SQLException ex){
Logger.getLogger(Student.class.getName()).log(Level.SEVERE, null, ex);


when I am executing this query(UPDATE STUDENT SET CURRENT_DATE='27TH MAY',SUBJECT='CRYPTOGRAPHY',ATTENDANCE='ABSENT' WHERE STU_ID='40';) in oracle 11g it works fine...but the same sql in eclipse returns error.

Answer Source

Your problem should be here:

if (rdbtnPresent.isSelected())
    sql+= "'"+Atdnc[0]+"',"; // --> this should be "'" as there is no more field
    sql+= "'"+Atdnc[1]+"'";
sql+="WHERE STU_ID='"+id+"'"; // --> this should start with a space sql+=" WHERE..

So you have 2 issues:

  1. If rdbtnPresent.isSelected() return true, there is a comma that has nothing to do here
  2. There is no space before your WHERE

NB: Consider using PrepareStatement instead to avoid this kind of issue, to avoid having to escape your values and to avoid SQL injection attacks.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download