package test_1; import java.sql.*; import java.util.Scanner; public class lianxi { public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("请输入考生信息"); System.out.println("Type:"); String t=sc.next(); System.out.println("IDCard:"); String id=sc.next(); System.out.println("ExamCard:"); String card=sc.next(); System.out.println("StudentName:"); String sn=sc.next(); System.out.println("Location:"); String lt=sc.next(); System.out.println("Grade:"); String g=sc.next(); System.out.println("信息录入成功!"); //连接数据库 Connection con=null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); String struil="jdbc:oracle:thin:@localhost:1521:ORCLER"; con=DriverManager.getConnection(struil, "test", "asd123"); System.out.println("连接数据库成功"); String sql="insert into examstudent(flowid,type,idcard,examcard,studentname,location,grade) values (lianxi.nextval,?,?,?,?,?,?)"; PreparedStatement ps=con.prepareStatement(sql); ps.setString(1, t); ps.setString(2, id); ps.setString(3, card); ps.setString(4, sn); ps.setString(5, lt); ps.setString(6, g); ps.executeUpdate(); ps.close(); } catch(Exception e) { e.printStackTrace(); System.out.println("连接数据库失败"); } }