java 连接Access数据库问题

来源:百度知道 编辑:UC知道 时间:2024/06/15 04:15:35
import java.sql.*;

public class AccessDemo
{
public static void main(String args[])
{
int id,score;
String name;

Connection con;
Statement stmt;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println("1:"+e.toString());
}

try
{
con=DriverManager.getConnection("jdbc:odbc:stuDataSource");

stmt=con.createStatement();

stmt.execute("insert into student(name,score) values('tom',19)");

stmt.close();
con.commit();
con.close();

System.out.println("OK!");
}
catch(SQLException e)
{
System.out.println(e.toString());
}
}
}

运行没错误 但是数据库没有更新 为什么啊?

stmt.execute("insert into student(name,score) values('tom',19)");
execute 只是单纯做数据查找的哦
要更新的话要用
executeUpdate

你试试把execute改成executeUpdate

crh1314的答案较王道
也有可能是你已经更新了一遍数据库,所以不能再更新了

运行没有错能不能读取数据呢?