package test_1; import java.sql.*; import java.util.Scanner; public class chaxun { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("a:准考证号"); System.out.println("b:身份证号"); System.out.println("请输入您要查询的类型:"); String s=sc.next(); System.out.println("请输入证件号:"); String z=sc.next(); 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("连接数据库成功"); Statement st= con.createStatement(); if(s.equals("a")) { ResultSet rs=st.executeQuery("select * from examstudent where examcard="+z); while(rs.next()) { String t=rs.getString("type"); String id=rs.getString("idcard"); String ex=rs.getString("examcard"); String stu=rs.getString("studentname"); String l=rs.getString("location"); String g=rs.getString("grade"); System.out.println("四/六级"+t+"身份证号"+id+"准考证号"+ex+"学生姓名"+stu+"区域"+l+"成绩"+g); } rs.close(); } else if(s.equals("b")) { ResultSet rs=st.executeQuery("select * from examstudent where idcard="+z); while(rs.next()) { String t=rs.getString("type"); String id=rs.getString("idcard"); String ex=rs.getString("examcard"); String stu=rs.getString("studentname"); String l=rs.getString("location"); String g=rs.getString("grade"); System.out.println("四/六级"+t+"身份证号"+id+"准考证号"+ex+"学生姓名"+stu+"区域"+l+"成绩"+g); } rs.close(); } else { System.out.println("您的输入有误,请重新输入!"); } st.close(); } catch(Exception e) { e.printStackTrace(); System.out.println("连接数据库失败"); } } }