只存一个就可以
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;
public class ex2 {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int i = 0;
//1.加载驱动
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("成功加载驱动");
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println("找不到sql驱动");
e.printStackTrace();
}
//定义链接数据库的URL地址
String url="jdbc:mysql://localhost:3306/examination?useSSL=false";
//2.建立连接
Connection conn=null;
try {
conn = (Connection) DriverManager.getConnection(url, "root","226793");
System.out.println("成功连接数据库");
}
catch (SQLException e){
System.out.println("连接数据库失败");
e.printStackTrace();
}
//3、在数据库中添加记录
String sql = "insert into judgemental(STem,True,False) values(?,?,?)";//?是占位符
PreparedStatement ps=null;
try {
ps = conn.prepareStatement(sql);
//填充占位符
System.out.println("请输入:");
ps.setString(1,"asdasd");//输入
ps.setString(2,"true");// 输入
ps.setString(3,"false ");//输入
//执行操作
ps.execute();
System.out.println("操作执行成功");
//4.关闭资源
ps.close();
conn.close();
}
catch (SQLException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println("添加失败");
}
//System.out.println("添加了"+Integer.toString(i-1)+"个学生");
}
}
你可以把错误异常打印一下,这个可以很方便的帮你判断问题出在哪