I won’t say much nonsense, I will just post the key code to you. The specific code is as follows:
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 automatically generated catch block e.printStackTrace();}}//Input function public String[] shuru() {System.out.println("Please enter the detailed information of the candidates in order: /n Exam level, ID number, admission ticket number, candidate's name, examination location, examination score"); Scanner sc = new Scanner(System.in);String[] str = new String[6];for (int i = 0; i < str.length; i++) {str[i] = sc.nextLine();}System.out.println("Information input is completed");sc.close();return str;}//Query function public String chaxun() {System.out.println("Please select query method: /na:ID number b:Admission ticket number");Scanner sc = new Scanner(System.in);String s = sc.nextLine().toLowerCase();String str = "";if (s.equals("a")) {System.out.println("Please enter query number: ");String st = sc.nextLine();if (st.length() == 18) {str = "select * from examstudent where idcard = " + st;} else {System.out.println("Is the number of digits entered incorrectly");}} else if (s.equals("b")) {System.out.println("Please enter the query number: ");String st = sc.nextLine();if (st.length() == 15) {str = "select * from examstudent where examcard = " + st;} else {System.out.println("Is the number of digits entered incorrectly");}} else {System.out.println("You entered incorrectly, please re-enter the program");}sc.close();return str;}//Delete the function public String shanchu() {Scanner sc = new Scanner(System.in);System.out.println("Please enter the candidate's admission ticket number: ");String str = sc.nextLine();if (str.length() != 15) {System.out.println("If the admission ticket number is entered incorrectly, please re-enter");}sc.close();return str;}//Run public void yunxing() {synchronized ("") {try {Connection conn = null;// Link database 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()+"Database connection successful");Statement st = conn.createStatement();// Select function Scanner sc = new Scanner(System.in);System.out.println("Please select function: /n 1: Input information 2: Query information 3: Delete information");int num = sc.nextInt();if (num == 1) {// Input information String[] str = shuru();if (str[1].length() != 18 && str[2].length() != 15) {System.out.println("The number of digits is incorrect (ID card number is 18 digits, admission ticket number is 15 digits), please re-enter the system and enter it");} else {st.execute("insert into examstudent values(fiowid.nextval,to_number(" + str[0] + "),'" + str[1]+ "','" + str[2] + "','" + str[3] + "','" + str[4] + "'," + "to_number(" + str[5]+ "))");System.out.println("Information entry was successful");}} else if (num == 2) {// Query String str1 = chaxun();ResultSet r = st.executeQuery(str1);// Output query result if (r.next()) {System.out.println("Exam Level:" + r.getString(2) + "/n ID number:" + r.getString(3) + "/n Admission Ticket number:"+ r.getString(4) + "/nCalling candidate's name: " + r.getString(5) + "/nExam Region: " + r.getString(6) + "/nExam Score: "+ r.getString(7));} else {System.out.println("No such person is found, please re-enter the system");}r.close();} else if (num == 3) {//Delete String str2 = shanchu();int a = st.executeUpdate("delete examstudent where examcard = " + str2);if (a > 0) {System.out.println("Delete successful");} else {System.out.println("No such person is found, please re-enter the program");}} else {System.out.println("Sorry, this function is not enabled yet");}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("Window1");lx1.start();// lx2.setName("Window2");// lx2.start();// lx3.setName("Window3");// lx3.start();}} Start running:
Information input: ID number query:
Admission ticket number query: Information deletion:
Enter an error message:
The above is the full description of the detailed explanation of the Oracle database code for Java connection operation introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!