Java authoring conditionally querying data in a database

Source: Internet
Author: User
Tags ticket

 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.