JDBC练习
Posted 厂公
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(); } } }
以上是关于JDBC练习的主要内容,如果未能解决你的问题,请参考以下文章
spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段
mysql jdbc源码分析片段 和 Tomcat's JDBC Pool
Python练习册 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-),(http://tieba.baidu.com/p/2166231880)(代码片段