博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java连接Oracle数据库练习题
阅读量:5334 次
发布时间:2019-06-15

本文共 5209 字,大约阅读时间需要 17 分钟。

   

package come.hanqi.test;import java.sql.*;import java.util.Scanner;public class Shujuku {    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", "wsjsk123");            Scanner sc = new Scanner(System.in);            System.out.println("请输入考生的详细信息");            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("StudentName:");            String d = sc.next();            System.out.println("Location:");            String e = sc.next();            System.out.println("Grade:");            int f = sc.nextInt();            System.out.println("信息录入成功!");            Statement st = conn.createStatement();            st.executeUpdate("insert into examstudent values( se_test.nextval," + a + ",'" + b + "','" + c + "','" + d                    + "','" + e + "'," + f + ")");            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 e1) {            e1.printStackTrace();            System.out.println("连接失败");        }            }}

package come.hanqi.test;import java.sql.*;import java.util.*;public class Chaxun {    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", "wsjsk123");            System.out.println("请选择您要输入的类型");            System.out.println("a:准考证号");            System.out.println("b:身份证号");            Scanner sc= new Scanner(System.in);            String s = sc.next();            if(s.equals("a"))            {                System.out.println("请输入准考证号");                String zkz=sc.next();                Statement st = conn.createStatement();                 ResultSet rs=st.executeQuery("select * from examstudent where ExamCard='"+ zkz+"'");                 while(rs.next())                 {                 System.out.println("流水号:"+ rs.getInt(1) + "   四级/六级:"+rs.getInt(2) + "   身份证号码:"+rs.getString(3)+ "   准考证号码:"+rs.getString(4)+ "   学生姓名:"+rs.getString(5)+ "   区域:"+rs.getString(6)+"   成绩:"+rs.getInt(7));                 }            }            else if(s.equals("b"))            {                System.out.println("请输入身份证号");                String sfz=sc.next();                Statement st = conn.createStatement();                 ResultSet rs=st.executeQuery("select * from examstudent where IDCard='"+ sfz+"'");                 while(rs.next())                 {                 System.out.println("流水号:"+ rs.getInt(1) + "   四级/六级:"+rs.getInt(2) + "   身份证号码:"+rs.getString(3)+ "   准考证号码:"+rs.getString(4)+ "   学生姓名:"+rs.getString(5)+ "   区域:"+rs.getString(6)+"   成绩:"+rs.getInt(7));                 }            }            else            {                System.out.println("您输入有误!请重新进入程序");            }           st.close();           rs.close();         } catch (Exception e1) {            e1.printStackTrace();            System.out.println("连接失败");        }    }}

package come.hanqi.test;import java.sql.*;import java.util.Scanner;public class Shanchu {    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", "wsjsk123");            System.out.println("请输入学生考号");            Scanner sc=new Scanner(System.in);            String s=sc.nextLine();            Statement st=conn.createStatement();              ResultSet rs=st.executeQuery("select * from examstudent");                              String del="delete examstudent where examcard="+s;                int j=st.executeUpdate(del);                if(j>0)                {                System.out.println("删除成功!");                }else                {                    System.out.println("查无此人!请重新进入程序...");                }        } catch (Exception e1) {            e1.printStackTrace();            System.out.println("连接失败");        }    }}

转载于:https://www.cnblogs.com/jskbk/p/5602691.html

你可能感兴趣的文章
PHP zip压缩文件及解压
查看>>
SOAP web service用AFNetWorking实现请求
查看>>
Java变量类型,实例变量 与局部变量 静态变量
查看>>
mysql操作命令梳理(4)-中文乱码问题
查看>>
Python环境搭建(安装、验证与卸载)
查看>>
一个.NET通用JSON解析/构建类的实现(c#)
查看>>
Windows Phone开发(5):室内装修 转:http://blog.csdn.net/tcjiaan/article/details/7269014
查看>>
详谈js面向对象 javascript oop,持续更新
查看>>
关于这次软件以及pda终端的培训
查看>>
jQuery上传插件Uploadify 3.2在.NET下的详细例子
查看>>
如何辨别一个程序员的水平高低?是靠发量吗?
查看>>
新手村之循环!循环!循环!
查看>>
正则表达式的用法
查看>>
线程安全问题
查看>>
SSM集成activiti6.0错误集锦(一)
查看>>
下拉刷新
查看>>
linux的子进程调用exec( )系列函数
查看>>
MSChart的研究
查看>>
C# 索引器
查看>>
MySQLdb & pymsql
查看>>