PackageLianxi2;ImportJava.sql.*;ImportJava.util.Scanner; Public classLianxi2 { Public Static voidMain (string[] args) {Connection conn=NULL; Try{class.forname ("Oracle.jdbc.driver.OracleDriver"); String strURL= "Jdbc:Oracle:thin: @localhost: 1521:orcl"; Conn= Drivermanager.getconnection (strURL, "Test1", "duibuqi19950220"); System.out.println ("Link Database success!" "); Statement St=conn.createstatement (); System.out.println ("Please enter your ID number or student test number"); System.out.println ("A: Social Security Number"); System.out.println ("B: Ticket Number"); Scanner b=NewScanner (system.in); String Str=B.next (); if(Str.equals ("a") {System.out.println ("Please enter your ID number"); String BB=B.next (); ResultSet RS= St.executequery ("select * from examstudent where idcard = '" +bb+ "'"); while(Rs.next ()) {intFlowid = Rs.getint (1); intType = Rs.getint (2); String Idcard= Rs.getstring (3); String Examcard= Rs.getstring (4); String Studentname= Rs.getstring (5); String Location= Rs.getstring (6); intGrade = Rs.getint (7); System.out.println ("Serial number is" +flowid+ "level 46" +type+ "ID number is" +idcard+ "student test number is" +examcard+ "name is" +studentname+ "in this city" +location+ "score is" +Grade); } } Else if(Str.equals ("B") {System.out.println ("Enter the ticket number:"); String AA=B.next (); ResultSet ru= St.executequery ("select * from examstudent where examcard = '" +aa+ "'"); while(Ru.next ()) {intFlowid = Ru.getint (1); intType = Ru.getint (2); String Idcard= Ru.getstring (3); String Examcard= Ru.getstring (4); String Studentname= Ru.getstring (5); String Location= Ru.getstring (6); intGrade = Ru.getint (7); System.out.println ("Serial number is" +flowid+ "level 46" +type+ "ID number is" +idcard+ "student test number is" +examcard+ "name is" +studentname+ "in this city" +location+ "score is" +Grade); } } Else{System.out.println ("Wrong input!" "); } } Catch(Exception e) {e.printstacktrace (); } }}
PackageLianxi2;ImportJava.sql.*;ImportJava.util.Scanner; Public classLianxi2 { Public Static voidMain (string[] args) {Connection conn=NULL; Try{class.forname ("Oracle.jdbc.driver.OracleDriver"); String strURL= "Jdbc:Oracle:thin: @localhost: 1521:orcl"; Conn= Drivermanager.getconnection (strURL, "Test1", "duibuqi19950220"); System.out.println ("Link Database success!" "); Statement St=conn.createstatement (); System.out.println ("Please enter your ID number or student test number"); System.out.println ("A: Social Security Number"); System.out.println ("B: Ticket Number"); Scanner b=NewScanner (system.in); String Str=B.next (); if(Str.equals ("a") {System.out.println ("Please enter your ID number"); String BB=B.next (); ResultSet RS= St.executequery ("select * from examstudent where idcard = '" +bb+ "'"); while(Rs.next ()) {intFlowid = Rs.getint (1); intType = Rs.getint (2); String Idcard= Rs.getstring (3); String Examcard= Rs.getstring (4); String Studentname= Rs.getstring (5); String Location= Rs.getstring (6); intGrade = Rs.getint (7); System.out.println ("Serial number is" +flowid+ "level 46" +type+ "ID number is" +idcard+ "student test number is" +examcard+ "name is" +studentname+ "in this city" +location+ "score is" +Grade); } } Else if(Str.equals ("B") {System.out.println ("Enter the ticket number:"); String AA=B.next (); ResultSet ru= St.executequery ("select * from examstudent where examcard = '" +aa+ "'"); while(Ru.next ()) {intFlowid = Ru.getint (1); intType = Ru.getint (2); String Idcard= Ru.getstring (3); String Examcard= Ru.getstring (4); String Studentname= Ru.getstring (5); String Location= Ru.getstring (6); intGrade = Ru.getint (7); System.out.println ("Serial number is" +flowid+ "level 46" +type+ "ID number is" +idcard+ "student test number is" +examcard+ "name is" +studentname+ "in this city" +location+ "score is" +Grade); } } Else{System.out.println ("Wrong input!" "); } } Catch(Exception e) {e.printstacktrace (); } }}
Java authoring conditionally querying data in a database