packagecom.hanqi.test;import java.sql.*;import java.util.*;public classLianXi {public static voidmain(String[] args) {
Connection conn= null;try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String strUrl= "jdbc:oracle:thin:@localhost:1521:orcl";
conn= DriverManager.getConnection(strUrl, "test", "5211314");
System.out.println("连接数据库成功!");
System.out.println("输入学生信息");
System.out.println("Type:");
Scanner a1=newScanner(System.in);int b1=a1.nextInt();
System.out.println("IDCard:");
Scanner a2=newScanner(System.in);
String b2=a2.next();
System.out.println("ExamCard:");
Scanner a3=newScanner(System.in);
String b3=a3.next();
System.out.println("StudentName:");
Scanner a4=newScanner(System.in);
String b4=a4.next();
System.out.println("Location:");
Scanner a5=newScanner(System.in);
String b5=a5.next();
System.out.println("Grade:");
Scanner a6=newScanner(System.in);int b6=a6.nextInt();
Statement st=conn.createStatement();
st.executeUpdate("insert into examstudent values( flowid.nextval,"+b1+",'"+b2+"','"+b3+"','"+b4+"','"+b5+"',"+b6+")");
ResultSet rs= st.executeQuery("select * from examstudent");while(rs.next())
{int FlowID= rs.getInt(1);int Type= rs.getInt(2);
String IDCard= rs.getString(3);
String ExamCard= rs.getString(4);
String StudentName= rs.getString(5);
String Location= rs.getString(6);int Grade = rs.getInt(7);
System.out.println("流水号:"+ FlowID + " 四级/六级:"+Type + " 身份证号码:"+IDCard+ " 准考证号码:"+ExamCard+ " 学生姓名:"+StudentName+ " 区域:"+Location+" 成绩:"+Grade);
System.out.println("信息录入成功");
}
rs.close();
st.close();
conn.close();
}catch(Exception e)
{//TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}