Nonsense not to say more, directly to everyone to paste the key code, the specific code 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);
The catch block (Interruptedexception e) {//TODO automatically generated catch blocks E.printstacktrace ();}
Input function Public string[] Shuru () {System.out.println () Enter the details of the examinee in order: \ n Test grade, ID number, ticket number, candidate name, Test place, test result ");
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 complete");
Sc.close ();
return str;
///Query function Public String Chaxun () {System.out.println ("Please select a query: \ n A: ID number B: Ticket number");
Scanner sc = new Scanner (system.in);
String s = Sc.nextline (). toLowerCase ();
String str = "";
if (S.equals ("a")) {System.out.println ("Please enter a query number:");
String st = Sc.nextline (); if (st.length () = =) {str = "SELECT * from examstudent where idcard =" + st;} else {System.out.println ("Incorrect ID number entered incorrectly");}
else if (s.equals ("B")) {System.out.println ("Please enter the query number:"); String st = Sc.nextline(); if (st.length () = =) {str = "SELECT * from examstudent where examcard =" + st;} else {System.out.println ("Input error of admission ticket");}
else {System.out.println ("you entered the query in error, please re-enter the program");} sc.close ();
return str;
///delete function public String Shanchu () {Scanner sc = new Scanner (system.in);
System.out.println ("Please enter Examinee's ticket number:");
String str = sc.nextline ();
if (Str.length ()!=) {System.out.println ("entry of the ticket number is incorrect, 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 succeeded");
Statement st = Conn.createstatement ();
Select function Scanner sc = new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Please select the function: \ n 1: Enter information 2: Query Information 3: Delete Information");
int num = Sc.nextint (); if (num = = 1) {//input information string[] str = Shuru (); if (Str[1].length ()!= && str[2].length ()!=) {System.out.println ("number of digits is wrong (ID number 18, ticket number 15), please re-enter the system input");} 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 success");
} else if (num = = 2) {//query String str1 = Chaxun ();
ResultSet r = st.executequery (STR1); Output query Result if (R.next ()) {System.out.println ("Exam Grade:" + r.getstring (2) + "\ n) ID Number:" + r.getstring (3) + "\ n" + "+" + R.getstri Ng (4) + "\ n Candidate Name:" + r.getstring (5) + "\ n Test Area:" + r.getstring (6) + "\ n Test results:" + r.getstring (7));}
else {System.out.println ("No this person, please re-enter the System");} r.close (); else if (num = = 3) {//delete String str2 = Shanchu (); int a = st.executeupdate ("delete examstudent where Examcard =" + St
R2); if (a > 0) {System.out.println ("delete succeeded");} else {System.out.println ("Do not check this person, re-enter program");}
else {System.out.println ("Sorry, temporarily not open this feature");} 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 ("Window 1");
Lx1.start ();
Lx2.setname ("Window 2");
Lx2.start ();
Lx3.setname ("Window 3");
Lx3.start (); }
}
Start running:
Information input: ID number inquiry:
Ticket Number query: Information Delete:
Enter the error message:
The above is a small series to introduce the Java connection operation Oracle Database code detailed description of all, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!