while trying to save record into Oracle 10g using java Swing the program terminates without executing -
hi, i'm trying save record oracle 10g using java swing program. when run program terminated
import java.awt.event.*; import java.sql.*; @suppresswarnings("serial") class insert extends jframe implements actionlistener { jlabel label,label1,label2,label3,label4,label5; jtextfield tf1,tf2,tf3,tf4,tf5; jbutton btn; connection con; insert() { super("inserting employee records"); label1 = new jlabel("empid:"); label1.setbounds(20,20,100,20); tf1 = new jtextfield(50); tf1.setbounds(130, 120, 200, 20); label2 = new jlabel("employeename:"); label2.setbounds(20, 150, 100, 20); tf2 = new jtextfield(100); tf2.setbounds(130, 150, 200, 20); label3 = new jlabel("gender:"); label3.setbounds(20, 180, 100, 20); tf3 = new jtextfield(50); tf3.setbounds(130, 180, 200, 20); label4 = new jlabel("dob:"); label4.setbounds(20, 210, 100, 20); tf4 = new jtextfield(50); tf4.setbounds(130, 210, 100, 20); label5 = new jlabel("doj"); label5.setbounds(130, 240, 100, 20); tf5 = new jtextfield(50); tf5.setbounds(130,270,100,20); btn = new jbutton("submit"); btn.setbounds(130, 300, 100, 20); btn.addactionlistener(this); add(label1); add(tf1); add(label2); add(tf2); add(label3); add(tf3); add(label4); add(tf4); add(label5); add(tf5); add(btn); tf1.seteditable(false); tf5.seteditable(false); } public void actionperformed(actionevent ae) { string id = tf1.gettext(); string name = tf2.gettext(); string gender = tf3.gettext(); string dob = tf4.gettext(); try { string url="jdbc:oracle:thin:@localhost:1521:xe"; string u="ems2"; string p="ems2"; class.forname("oracle.jdbc.driver.oracledriver"); con=drivermanager.getconnection(url,u,p); preparedstatement st = con.preparestatement("insert employee"+"(emp_id,"+"employeename,"+"gender,"+"dob,"+"doj)"+"values(?,?,?,?,?)"); st.setstring(1, id); st.setstring(2,name); st.setstring(3,gender); st.setstring(4, dob); st.executeupdate(); joptionpane.showmessagedialog(null, "data inserted database"); con.close(); } catch(exception ex) { system.out.println(ex); } } public static void main(string [] args) { new insert(); } }e
your not showing insert jframe
. try do:
new insert().setvisible(true);
Comments
Post a Comment