這裏之後更新是代碼數據庫是沒有得到執行該程序
import java.sql.*;
public class Insertdb {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con= DriverManager.getConnection("jdbc:odbc:Dsn1");
PreparedStatement ps= con.prepareStatement("insert into Table1 values (?,?,?)");
ps.setInt(1,1);
ps.setString(2,"Sachin");
ps.setInt(3,25000);
int i=ps.executeUpdate();
if(i>0)
{
System.out.println(i +"records inserted");
}
}
catch(Exception e)
{
System.out.println(e);
}
// TODO code application logic here
}
}
中使用的數據的基礎上是MS訪問2013年 上述代碼的控制檯上的輸出是:插入1個記錄
但是,當我打開數據庫記錄沒有插入。代碼中有任何錯誤嗎?如果不是什麼可能出錯?
可能你需要提交事務 – xwhyz
如何提交事務? – user3249242
關閉所有連接,結果集和語句,然後檢查。 –