| 发表于:2008-01-23 10:05:06 楼主 |
我用java写的程序,用access连接,odbc都配好了,运行的时候也不出错,可是数据就是不写入,也显示不出来,我是初学,所以大部分代码都是按书上写的,可还是写不进去,希望高手可指教一下,不胜感激!!!! public void jbutton2_actionperformed(actionevent e) throws sqlexception { string dbdriver="sun.jdbc.odbc.jdbcodbcdriver"; string connectionstr="jdbc:odbc:db1"; connection con = null; statement stmt = null; string i=null; try {class.forname(dbdriver); con = drivermanager.getconnection(connectionstr, "", ""); stmt = con.createstatement(); string n = jtextfield2.gettext(); // string sex = (string) jcombobox1.getselecteditem(); string id= jtextfield3.gettext(); string d = jtextfield1.gettext(); // string type = jtextfield5.gettext(); i = "insert into inf(name,id,date) values('" + n + "','" + id + "','" + d + "')"; stmt.EXECuteupdate(i); stmt.close(); con.close(); } catch (exception ex1) {} joptionpane.showmessagedialog(null, "信息输入成功!", "用户提示", joptionpane.information_message); jtextfield1.settext(""); jtextfield2.settext(""); jtextfield3.settext(""); //jtextfield4.settext(""); } |
|
|
|
|