查看: 1253|回复: 2
|
JAVA PROGRAMMING
[复制链接]
|
|
请问谁知道从JAVA INSERT DATA 进DATABASE MS ACCESS 的两个TABLE 要怎样??
酱些可以吗?
String url = "jdbc:odbc:library";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String theStatement="INSERT INTO Member (MemberID, Name, UserID, Password, TelNo, Email) VALUES ('"+ jTextFieldID.getText() + "','" + jTextFieldName.getText() + "','" + jTextFieldUser.getText() + "','" + jTextFieldPass.getText() + "','" + jTextFieldTel.getText() + "','"+ jTextFieldEmail.getText() + "')";
String theStatement2="INSERT INTO Student(RegisterNo ) VALUES ('"+ jTextFieldID.getText() + "')";
System.out.println(theStatement);
System.out.println(theStatement2);
try {
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
String loc = "jdbc:odbc:librarysystem";
con = DriverManager.getConnection (loc);
}
catch (ClassNotFoundException cnf) {
JOptionPane.showMessageDialog (null, "Driver not Loaded...");
System.exit (0);
}
catch (SQLException sqlex) {
JOptionPane.showMessageDialog (null, "Unable to Connect to Database...");
System.exit (0);
}
setVisible (true);
try
{
Class.forName(driver);
Connection connection=DriverManager.getConnection(url);
Statement querylibrary=connection.createStatement();
int result = querylibrary.executeUpdate(theStatement);
int result2 = querylibrary.executeUpdate(theStatement2);
if ( result == 1 ){
System.out.print( "\nOrder Placed\n" );
JOptionPane.showMessageDialog (this, "Record has been Saved.");
jTextFieldID.setText(null);}
else{
System.out.print( "\nInsertion failed\n" );
JOptionPane.showMessageDialog (this, "Problem while Saving the Record.");}
querylibrary.close();
connection.close();
}
* 版主帮你编辑了禁用 Smilies,不然一大堆表情符号难于解读 *
[ 本帖最后由 白日梦 于 18-10-2005 04:07 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 18-10-2005 10:33 PM
|
显示全部楼层
你的err msg 呢?
可以看见..有try,怎么没有catch呢? 还是这是刚出的新方法?
还有
Class.forName(driver);
Connection connection=DriverManager.getConnection(url);
以上怎么会重复2次呢?
可见你对JDBC不了解..
try
{
Class.forName(driver);
Connection connection=DriverManager.getConnection(url);
.. |
|
|
|
|
|
|
|
楼主 |
发表于 21-11-2005 04:06 PM
|
显示全部楼层
原帖由 jasonmun 于 18-10-2005 10:33 PM 发表
你的err msg 呢?
可以看见..有try,怎么没有catch呢? 还是这是刚出的新方法?
还有
Class.forName(driver);
Connection connection=DriverManager.getConnection(url);
以上怎么会重复2次呢?
可见你对J ...
对哦...我都没发觉.....唉.... |
|
|
|
|
|
|
| |
本周最热论坛帖子
|