Qdmin
0dmin
2015-06-13 09:12

Java执行SQL的insert语句

  • 数据库
  • ava
  • sql

public class JDBC_2 {
public static void main(String[] args) {
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/xskc";
String user = "root";
String pwd = "mch0dmin";
java.sql.Connection con = DriverManager.getConnection(url, user, pwd);
//java.sql.Statement stmt = con.createStatement();
Statement stmt = null;
String sql = "insert into student values('95005', '张三', '男', 50, 'DC')";
//String sql = "select sno from student";
stmt.executeQuery(sql);

        如果执行的是注释中的select语句,就不会报错,按时执行insert语句,就出现问题,请大牛帮帮忙!谢谢!
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

9条回答

为你推荐

换一换