Create DATABASE table Examstudent

Source: Internet
Author: User

 Packagecom.hanqi.test;ImportJava.sql.*;ImportJava.util.*; Public classLianxi { 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, "test", "5211314"); System.out.println ("Connection to the database was successful!" "); System.out.println ("Enter student Information"); System.out.println ("Type:"); Scanner A1=NewScanner (system.in); intb1=A1.nextint (); System.out.println ("Idcard:"); Scanner A2=NewScanner (system.in); String B2=A2.next (); System.out.println ("Examcard:"); Scanner A3=NewScanner (system.in); String B3=A3.next (); System.out.println ("Studentname:"); Scanner A4=NewScanner (system.in); String B4=A4.next (); System.out.println ("Location:"); Scanner A5=NewScanner (system.in); String b5=A5.next (); System.out.println ("Grade:"); Scanner A6=NewScanner (system.in); intb6=A6.nextint (); Statement St=conn.createstatement (); St.executeupdate ("INSERT into examstudent values (Flowid.nextval," +b1+ "," +b2+ "', '" +b3+ "', '" +b4+ "', '" +b5+ "'," +b6+ ")"); ResultSet RS= St.executequery ("SELECT * from Examstudent");  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:" + Flowid + "level four/Six:" +type + "ID Number:" +idcard+ "admission Ticket Number:" +examcard+ "Student Name:" +studentname+ "area:" +location+ " Score: "+Grade); System.out.println ("Information Entry Success");            } rs.close ();            St.close ();                    Conn.close (); }         Catch(Exception e) {//TODO Auto-generated catch blockE.printstacktrace (); }    }}

Create a Java program in eclipse: Enter a social Security number or a ticket number to check the student's basic information.

 Packagecom.hanqi.test;ImportJava.sql.*;ImportJava.util.*; Public classChaxun { 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, "test", "5211314"); System.out.println ("Connection to the database was successful!" "); System.out.println ("Please select the type you want to enter:"); System.out.println ("A: Ticket number"); System.out.println ("B: Social Security Number"); Scanner Shuru=NewScanner (system.in); String Str=Shuru.nextline (); if(!str.equals ("a") &&!str.equals ("B")) {System.out.println ("You entered the wrong!" Please re-enter the program: "); System.exit (-1); } System.out.println ("Please enter a number"); Scanner Haoma=NewScanner (system.in); String str1=Haoma.nextline (); Statement St=conn.createstatement (); ResultSet RS=st.executequery ("SELECT * from Examstudent");  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); if(Str.equals ("a"))                   {                                          if(Str1.equals (Examcard)) {System.out.println ("Serial number:" + Flowid + "level four/Six:" +type + "ID Number:" +idcard+ "admission Ticket Number:" +examcard+ "Student Name:" +studentname+ "area:" +location+ " Score: "+Grade); }                   }                   Else if(Str.equals ("B"))                   {                       if(Str1.equals (Idcard)) {System.out.println ("Serial number:" + Flowid + "level four/Six:" +type + "ID Number:" +idcard+ "admission Ticket Number:" +examcard+ "Student Name:" +studentname+ "area:" +location+ " Score: "+Grade); }                     }                                  }

Rs.close ();
St.close ();
Conn.close ();

                 }         catch  (Exception e)         {            //  TODO Auto-generated catch block             e.printstacktrace ();     }}}

Complete deletion of student information

 Packagecom.hanqi.test;ImportJava.sql.*;ImportJava.util.*; Public classShanchu { 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, "test", "5211314"); System.out.println ("Connection to the database was successful!" "); System.out.println ("Please enter student's test number:"); @SuppressWarnings ("Resource") Scanner Haoma=NewScanner (system.in); String Str=Haoma.nextline (); Statement St=conn.createstatement (); ResultSet RS=st.executequery ("SELECT * from Examstudent");  while(Rs.next ()) {String Examcard= Rs.getstring (4); if(Str.equals (Examcard)) {St.execute ("Delete from examstudent t where t.examcard= '" +examcard+ ""); System.out.println ("Delete succeeded!" ");                           Rs.close ();                           St.close ();                                                       Conn.close (); System.exit (-1); }} System.out.println ("Do not check this person, please re-enter the program ...");            Rs.close ();            St.close ();                             Conn.close (); }         Catch(Exception e) {//TODO Auto-generated catch blockE.printstacktrace (); }    }}

Create DATABASE table Examstudent

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.