在数据库中看不到使用program插入的值。下面是我用来做同样事情的代码
import java.util.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class JDBC {
private static Scanner sc;
public static void main(String args[]) throws Exception {
sc = new Scanner(System.in);
System.out.println("hii");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/rsystems", "root", "rsystems");
PreparedStatement stmt = con.prepareStatement("insert into user valiues(?,?)");
System.out.println("Enter id:");
int no = sc.nextInt();
System.out.println("Enter name:");
String name = sc.next();
stmt.setInt(1, no);
stmt.setString(2, name);
//I think I need to commit over here and I have tried the same but even with that I didn't see my inserted data in database
}
}发布于 2015-07-29 13:11:22
您的查询是错误的,并且您永远不会执行它。
PreparedStatement stmt = con.prepareStatement("insert into user values(?,?)");
stmt.execute();https://stackoverflow.com/questions/31691596
复制相似问题