JDBC练习
package com.test; import java.sql.*; import java.sql.Date; import java.util.*; public class examstudent { public static void main(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", "jiayou123"); Statement st=conn.createStatement(); System.out.println("请输入考生的详细信息"); Scanner sc=new Scanner(System.in); System.out.println("Type:"); int a=sc.nextInt(); System.out.println("IDCARD:"); String b=sc.next(); System.out.println("EXAMCARD:"); String c=sc.next(); System.out.println("StudentNmae:"); String d=sc.next(); System.out.println("Location:"); String e=sc.next(); System.out.println("Grade:"); String f=sc.next(); int i=st.executeUpdate("insert into examstudent values (se_tset.nextval,"+a+",'"+b+"','"+c+"','"+d+"','"+e+"',"+f+")"); if (i>0) { System.out.println("信息录入成功"); } //第一题 System.out.println("请选择需要输入的类型:"); String str="a:准考证号"; String str1="b:身份证号"; System.out.println(str); System.out.println(str1); String str2=sc.next(); if(str2.equals("a")) { System.out.println("请输入准考证号:"); String str3=sc.next(); ResultSet rs=st.executeQuery("select * from EXAMSTUDENT where ExamCard='"+str3+"'"); while(rs.next()) { String FlowID=rs.getString("FlowID"); String Type=rs.getString("Type"); String IDCard=rs.getString("IDCard"); String ExamCard=rs.getString("ExamCard"); String StudentName=rs.getString("StudentName"); String Location=rs.getString("Location"); String Grade=rs.getString("Grade"); System.out.println("FlowID:"+FlowID+"Type:"+Type+"IDCard:" +IDCard+"ExamCard:"+ExamCard+"StudentName:"+StudentName+"Location:"+Location+"Grade:"+Grade); } rs.close(); } else if(str2.equals("b")) { System.out.println("请输入身份证号:"); String str3=sc.next(); ResultSet rs=st.executeQuery("select * from EXAMSTUDENT where IDCard='"+str3+"'"); while(rs.next()) { String FlowID=rs.getString("FlowID"); String Type=rs.getString("Type"); String IDCard=rs.getString("IDCard"); String ExamCard=rs.getString("ExamCard"); String StudentName=rs.getString("StudentName"); String Location=rs.getString("Location"); String Grade=rs.getString("Grade"); System.out.println("FlowID:"+FlowID+"Type:"+Type+"IDCard: " +IDCard+"ExamCard:"+ExamCard+"StudentName:"+StudentName+"Location:"+Location+"Grade:"+Grade); } rs.close(); } else { System.out.println("您输入有误!请重新进入程序"); } //第二题 System.out.println("请输入学生的考号:"); String str11=sc.next(); ResultSet rs=st.executeQuery("select * from EXAMSTUDENT"); while(rs.next()) { if(str.equals(rs.getString("ExamCard"))) { st.executeUpdate("delete from examstudent where EXAMcard='"+str11+"'"); System.out.println("删除成功"); System.exit(1); } } System.out.println("查无此人!请重新进入程序");//第三题 rs.close(); st.close(); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } }