This is my table in oracle:
CREATE TABLE "STUDENT"
( "STU_ID" NUMBER(10,0),
"NAME" VARCHAR2(20),
"MOBILENO" NUMBER(10,0),
"EMAIL" VARCHAR2(50),
"ADDRESS" VARCHAR2(100),
"STREAM" CHAR(50),
"SEMESTER" CHAR(50),
"DATE_OF_BIRTH" DATE,
CONSTRAINT "PK_STU_ID" PRIMARY KEY ("STU_ID") ENABLE
) ;
I want to store student information in the above table by pressing the add button in eclipse.getting missing expression error when tries to execute this line"st.executeUpdate(sql);",here is the code:
JLabel lblAdd = new JLabel(" Add");
lblAdd.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
Clock=new Timer(5000,null);
Clock.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
try {
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE","ADMIN","admin");
Statement st=con.createStatement();
ResultSet rslt=st.executeQuery("select * from student");
ResultSet stu_seq=st.executeQuery("select student_sequence.nextval from DUAL");
System.out.println("getting resultset");
if(stu_seq.next())
{ System.out.println(stu_seq.getInt(1));
String name=txtNm.getText().trim();
String email=txtEmailid.getText().trim();
String mobile=txtMobileNo.getText().trim();
String sql="INSERT INTO student(STU_ID,NAME,MOBILENO,EMAIL,ADDRESS,DATE_OF_BIRTH,STREAM,SEMESTER) VALUES ("+stu_seq.getInt(1)+",'"+name+"','"+mobile+"','"+email+"',";
sql+="'"+txtPrmntAdd.getText().trim()+"',";
sql+="'"+cmbDay.getSelectedItem()+"'";
sql+="'"+cmbMnth.getSelectedItem()+"'";
sql+="'"+cmbYr.getSelectedItem()+"',";
sql+="'"+cmbRgstrStrm.getSelectedItem()+"',";
sql+="'"+cmbRgstrSem.getSelectedItem()+"',";
sql+=")";
st.executeUpdate(sql);
// System.out.println("after executing");
}
System.out.println("Inserted into database");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
frameReset();
//lblStatus.setText("data saved successfully");
//lblAni.setVisible(false);
Clock.stop();
}
});
Clock.start();
//lblStatus.setVisible(true);
//lblAni.setVisible(true);
}
});
lblAdd.setBounds(172, 340, 60, 18);
panelRegister.add(lblAdd);
lblAdd.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
lblAdd.setForeground(new Color(0, 51, 102));
lblAdd.setFont(new Font("Tw Cen MT", Font.PLAIN, 16));
lblAdd.setIcon(new ImageIcon(Student.class.getResource("/img/Add-New-16.png")));
want to store student information in the table.where I am doing wrong so that I am getting missing expression error?