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(); } }
开始运行:
信息输入: 身份证号查询:
准考证号查询: 信息删除:
输入错误信息: