JDBC Query Data Exercise

Source: Internet
Author: User
Tags ticket

 PackageCome.hanqi;ImportJava.sql.*;ImportJava.util.Scanner; Public classtest4 { Public Static voidMain (string[] args) {Scanner sc=NewScanner (system.in); System.out.println ("Please select the type you want to enter:"); System.out.println ("" + "A: Social Security Number"); System.out.println ("" + "B: Ticket Number"); String s=Sc.next (); Connection Conn=NULL; Try{class.forname ("Oracle.jdbc.OracleDriver"); String URL= "Jdbc:oracle:thin: @localhost: 1521:orcl"; Conn= Drivermanager.getconnection (URL, "Test1", "574004"); System.out.println ("Connection Database succeeded"); Statement St=conn.createstatement (); if(S.equals ("a"))             {                 for(inti = 0; I < 9; i++) {System.out.println ("Please enter your ID number:"); String ID=Sc.next (); String Idcard= "SELECT * from Examstudent t where idcard=" +ID; ResultSet RS=st.executequery (Idcard); if(ID! = "Select Idcard from Examstudent T") {System.out.println ("Input Error Please re-enter"); I--; }                     while(Rs.next ()) {String fl= rs.getstring (1); String Ty= Rs.getstring (2); String ID= Rs.getstring (3); String ex= Rs.getstring (4); String Stu= Rs.getstring (5); String Lo= Rs.getstring (6); String GA= Rs.getstring (7); System.out.println ("Flowid=" + FL + ", type=" + Ty + ", idcard=" + ID + ", examcard=" + ex + ", Name:" + Stu + ", birthplace: "+ Lo +", Score: "+GA); }                }            }             Else if(S.equals ("B"))            {                 for(inti = 0; I < 9; i++) {System.out.println ("Please enter the ticket number:"); String EX=Sc.next (); String Excard= "SELECT * from Examstudent t where examcard=" +EX; ResultSet RS=st.executequery (Excard); if(EX! = "Select Examcard from Examstudent T") {System.out.println ("You entered the error, please re-enter"); }                     while(Rs.next ()) {String fl= rs.getstring (1); String Ty= Rs.getstring (2); String ID= Rs.getstring (3); String ex= Rs.getstring (4); String Stu= Rs.getstring (5); String Lo= Rs.getstring (6); String GA= Rs.getstring (7); System.out.println ("Flowid=" + FL + ", type=" + Ty + ", idcard=" + ID + ", examcard=" + ex + ", Name:" + Stu + ", birthplace: "+ Lo +", Score: "+GA); }                }            }            Else{System.out.println ("You entered the wrong"); }        }        Catch(Exception e) {//TODO Auto-generated catch blockE.printstacktrace (); System.out.println ("Failed to connect to database"); }    }}

JDBC Query Data Exercise

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.