当前位置: 代码迷 >> Java相关 >> [求助]数据库插入语句为什么没成功?
  详细解决方案

[求助]数据库插入语句为什么没成功?

热度:161   发布时间:2007-07-13 11:25:55.0
[求助]数据库插入语句为什么没成功?
下面是我写的向数据库插入数据的代码,编译和执行都没有错误.但是我查看表时
却没有发现我插入的记录.这是为什么?帮帮忙
import java.sql.*;
public class Demo {
protected final String driver="sun.jdbc.odbc.JdbcOdbcDriver";
protected final String source="jdbc:odbc:link";
protected Connection connection;
protected Statement statement;
public void mm()throws SQLException{
Class.forName(driver);
//创建一个用于执行简单SQL的语句对象
statement=connection.createStatement();
String sql="INSERT INTO link(id,name) VALUES(10,'ttom')";
statement.executeUpdate(sql);
statement.close();

}
public static void main(String[] args) throws SQLException{
Demo m=new Demo();
m.mm();

}
}
搜索更多相关的解决方案: 数据库  语句  

----------------解决方案--------------------------------------------------------
import java.sql.*;
public class Demo {
protected final String driver="sun.jdbc.odbc.JdbcOdbcDriver";
protected final String source="jdbc:odbc:link";
protected Connection connection;
protected Statement statement;
public void mm()throws SQLException{
Class.forName(driver);
connecton=DriverManager.getConnection(source,"","") //说明后面的""为用户名和密码,没有可以不设.
//创建一个用于执行简单SQL的语句对象
statement=connection.createStatement();
String sql="INSERT INTO link(id,name) VALUES(10,'ttom')";
statement.executeUpdate(sql);
statement.close();

}
public static void main(String[] args) throws SQLException{
Demo m=new Demo();
m.mm();

}
}
----------------解决方案--------------------------------------------------------
  相关解决方案