package com.sp.test;

 import java.sql.*;
import java.util.*; public class Text_lianxi extends Thread {
public void run() {
try {
yunxing();
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} }
//输入函数
public String[] shuru() {
System.out.println("请按顺序依次输入考生的详细信息:\n考试等级,身份证号,准考证号,考生姓名,考试地点,考试成绩");
Scanner sc = new Scanner(System.in);
String[] str = new String[];
for (int i = 0; i < str.length; i++) {
str[i] = sc.nextLine();
}
System.out.println("信息输入完毕");
sc.close();
return str;
}
//查询函数
public String chaxun() {
System.out.println("请选择查询方式:\n a:身份证号 b:准考证号");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine().toLowerCase();
String str = "";
if (s.equals("a")) {
System.out.println("请输入查询号码:");
String st = sc.nextLine();
if (st.length() == 18) {
str = "select * from examstudent where idcard = " + st;
} else {
System.out.println("身份证位数输入有误");
}
} else if (s.equals("b")) {
System.out.println("请输入查询号码:");
String st = sc.nextLine();
if (st.length() == 15) {
str = "select * from examstudent where examcard = " + st;
} else {
System.out.println("准考证位数输入有误");
}
} else {
System.out.println("你输入的查询方式有误,请重新进入程序");
}
sc.close();
return str;
}
//删除函数
public String shanchu() {
Scanner sc = new Scanner(System.in);
System.out.println("请输入考生的准考证号:");
String str = sc.nextLine();
if (str.length() != 15) {
System.out.println("准考证号输入有误,请重新输入");
}
sc.close();
return str;
}
//运行
public void yunxing() {
synchronized ("") {
try {
Connection conn = null;
// 链接数据库
Class.forName("oracle.jdbc.driver.OracleDriver");
String strURL = "jdbc:oracle:thin:@localhost:1521:SP";
conn = DriverManager.getConnection(strURL, "test", "123");
System.out.println(Thread.currentThread().getName()+"数据库连接成功");
Statement st = conn.createStatement();
// 选择功能
Scanner sc = new Scanner(System.in);
System.out.println("请选择功能:\n 1:输入信息 2:查询信息 3:删除信息");
int num = sc.nextInt();
if (num == 1) {
// 输入信息
String[] str = shuru();
if (str[].length() != 18 && str[].length() != 15) {
System.out.println("号码位数有误(身份证号18位,准考证号15位),请重新进入系统输入");
} else {
st.execute("insert into examstudent values(fiowid.nextval,to_number(" + str[] + "),'" + str[1]
+ "','" + str[2] + "','" + str[3] + "','" + str[4] + "'," + "to_number(" + str[]
+ "))");
System.out.println("信息录入成功");
}
} else if (num == 2) {
// 查询
String str1 = chaxun();
ResultSet r = st.executeQuery(str1);
// 输出查询结果
if (r.next()) {
System.out.println("考试等级:" + r.getString(2) + "\n身份证号:" + r.getString(3) + "\n准考证号:"
+ r.getString(4) + "\n考生姓名:" + r.getString(5) + "\n考试地区:" + r.getString(6) + "\n考试成绩:"
+ r.getString(7));
} else {
System.out.println("查无此人,请重新进入系统");
}
r.close();
} else if (num == 3) {
// 删除
String str2 = shanchu();
int a = st.executeUpdate("delete examstudent where examcard = " + str2);
if (a > 0) {
System.out.println("删除成功");
} else {
System.out.println("查无此人,请重新进入程序");
}
} else {
System.out.println("抱歉,暂未开放此功能");
}
sc.close();
st.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} public static void main(String[] args) { Text_lianxi lx1 = new Text_lianxi();
// Text_lianxi lx2 = new Text_lianxi();
// Text_lianxi lx3 = new Text_lianxi(); lx1.setName("窗口1");
lx1.start();
// lx2.setName("窗口2");
// lx2.start();
// lx3.setName("窗口3");
// lx3.start(); } }

开始运行:

信息输入:                                                                                                身份证号查询:

                                        

准考证号查询:                                                                                               信息删除:

                                                             

输入错误信息:

                                                         

最新文章

  1. AOJ 0558 Cheese【BFS】
  2. bootstrap中如何让响应式图片(img-responsive)水平居中
  3. java.io.File中的pathSeparator与separator的差异
  4. POJ3258 River Hopscotch
  5. 实现手机扫描二维码页面登录,类似web微信-第三篇,手机客户端
  6. 读&gt;&gt;&gt;&gt;白帽子讲Web安全&lt;&lt;&lt;&lt;摘要→我推荐的一本书→1
  7. HIVE配置文件
  8. Typecho集成ueditor笔记
  9. iOS-制作Framework
  10. 游戏开发设计模式之状态模式 &amp; 有限状态机 &amp; c#委托事件(unity3d 示例实现)
  11. MySQL数据库IO问题
  12. JVM堆外内存随笔
  13. java回调机制——基本理解
  14. 若快打码平台python开发文档修改版
  15. 【C++ Primer | 15】C++类内存分布
  16. 怎么判断pagecontrol下的TabSheet是否打开还是关闭求答案
  17. ASP.NET HttpModule URL 重写 (一) 【Z】
  18. 【翻译】std::remove - C++ Reference
  19. vue-cli 项目构建性能分析工具
  20. JavaScript 代码小片段

热门文章

  1. hdoj 1013Digital Roots
  2. 编写shell脚本获取本机的网络地址。&amp;#160; 比方:本机的ip地址是:192.168.100.2/255.255.255.0,那么它的网络地址是&amp;#160;192.168.100.1/255.255.255.
  3. Android简单实现BroadCastReceiver广播机制
  4. 为什么不能用memcached存储Session?
  5. Android tablayout增加选择tab 的事件.
  6. dialog.setCancelable与setCanceledOnTouchOutside的区别
  7. mybatis批量插入、批量更新和批量删除
  8. HDU 1166 敌兵布阵【线段树 单点更新】
  9. pthread_cleanup_push
  10. canvas 连线曲线图封装