JDBC Performance Management System

Source: Internet
Author: User

Importjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;Importjava.sql.Statement;ImportJava.util.Scanner; Public classStudent { Public Static voidMain (String args[]) {Try{class.forname ("Com.mysql.jdbc.Driver");//load MySQL JDBC driver//System.out.println ("Success loading Mysql driver!");    }    Catch(Exception e) {System.out.print ("Error Loading Mysql driver!");    E.printstacktrace ();  } menu (); }     Public Static voidmenu () {System.out.println ("****************** Student personal achievement Management System ***********"); System.out.printf ("\ n",NULL); System.out.println ("1, increase results"); System.out.println ("2, revise the results"); System.out.println ("3, delete results"); System.out.println ("4, Query Results"); System.out.println ("5, Show All"); System.out.println ("6, Exit System"); System.out.printf ("\ n",NULL); System.out.println ("************************************************"); System.out.println ("Please enter the function number (1-6):"); Scanner R0=NewScanner (system.in); inti =R0.nextint (); Switch(i) { Case1: Add (); Try{Thread.Sleep (2000); } Catch(interruptedexception e) {e.printstacktrace (); }           Break;  Case2: Update ();  Break;  Case3: Del (); Try{Thread.Sleep (2000); } Catch(interruptedexception e) {e.printstacktrace (); }                       Break;  Case4: Find (); Try{Thread.Sleep (2000); } Catch(interruptedexception e) {e.printstacktrace (); }                   Break;  Case5: ShowAll (); Try{Thread.Sleep (2000); } Catch(interruptedexception e) {e.printstacktrace (); }           Break;  Case6: Break; default: System.out.println ("Please enter the number 1 to 6"); Try{Thread.Sleep (2000); } Catch(interruptedexception e) {e.printstacktrace (); }       Break;  } r0.close (); }  Public Static voidAdd () {Scanner SC=NewScanner (system.in); System.out.println ("Please enter new student information, enter the format for the school number, name, and score." such as: 201220201032 Xu 78.5 "); String input=Sc.nextline (); string[] AddItem=input.split (""); if(additem.length==3){         Try{Connection Connect=Drivermanager.getconnection ("Jdbc:mysql://localhost:3306/stumana", "root", "root"); Statement stmt=connect.createstatement (); intrs = stmt.executeupdate ("INSERT into student (id,name,grades) VALUES ('" +additem[0]+ "', '" +additem[1]+ "', '" +additem[2] + "')"); if(rs==1) System.out.println ("Added successfully! "); }           Catch(Exception e) {System.out.print ("Get Data error!");           E.printstacktrace (); }                             }       }  Public Static voidUpdate () {Scanner SC=NewScanner (system.in); System.out.println ("Please enter student number"); String ID=Sc.nextline (); Try{Connection Connect=Drivermanager.getconnection ("Jdbc:mysql://localhost:3306/stumana", "root", "root"); Statement stmt=connect.createstatement (); ResultSet RS= Stmt.executequery ("SELECT * from student where name= '" +id+ "'"); if(rs!=NULL) {System.out.println ("Please enter new student information, enter the format for the school number, name, and score." such as: 201220201032 Xu 78.5 "); String input=Sc.nextline (); string[] AddItem=input.split (""); if(additem.length==3){                         intRs1 = stmt.executeupdate ("Update student set id= '" +additem[0]+ "', Name= '" +additem[1]+ "', grades= '" +additem[2]+ "' where Id= ' "+id+" ' "); if(rs1==1) System.out.println ("Modified successfully!" "); }} free (NULL, stmt, connect); }        Catch(Exception e) {System.out.print ("Get Data error!");        E.printstacktrace (); }  }  Public Static voiddel () {Scanner SC=NewScanner (system.in); System.out.println ("Please enter student number"); String ID=Sc.nextline (); Try{Connection Connect=Drivermanager.getconnection ("Jdbc:mysql://localhost:3306/stumana", "root", "root"); Statement stmt=connect.createstatement (); intrs = stmt.executeupdate ("Delete from student where name= '" +id+ "'"); if(rs==1) System.out.println ("Delete succeeded!" "); Free (NULL, stmt, connect); }        Catch(Exception e) {System.out.print ("Get Data error!");        E.printstacktrace (); } }   Public Static voidfind () {Scanner SC=NewScanner (system.in); System.out.println ("Please enter student's name"); String name=Sc.nextline (); Try{Connection Connect=Drivermanager.getconnection ("Jdbc:mysql://localhost:3306/stumana", "root", "root"); Statement stmt=connect.createstatement (); ResultSet RS= Stmt.executequery ("SELECT * from student where name= '" +name+ "'"); System.out.print ("id" + ""); System.out.print ("Name" + ""); System.out.println (Results);  while(Rs.next ()) {System.out.print (rs.getstring ("id") + ""); System.out.print (Rs.getstring ("Name") + ""); System.out.println (Rs.getfloat ("Grades"));        } free (rs,stmt, connect); }        Catch(Exception e) {System.out.print ("Get Data error!");        E.printstacktrace (); } }   Public Static voidShowAll () {Try{Connection Connect=Drivermanager.getconnection ("Jdbc:mysql://localhost:3306/stumana", "root", "root"); //connection URL is jdbc:mysql//server address/database name, the following 2 parameters are login username and password, respectively//System.out.println ("Success connect Mysql server!");Statement stmt =connect.createstatement (); ResultSet RS= Stmt.executequery ("SELECT * FROM Student"); //User is the name of your tableSystem.out.print ("id" + "" "); System.out.print ("Name" + ""); System.out.println (Results);  while(Rs.next ()) {System.out.print (rs.getstring ("id") + ""); System.out.print (Rs.getstring ("Name") + ""); System.out.println (Rs.getfloat ("Grades"));         } free (rs,stmt, connect); }        Catch(Exception e) {System.out.print ("Get Data error!");        E.printstacktrace (); } }   Public Static voidFree (ResultSet resultset,statement st,connection conn) {Try{        if(resultset!=NULL) Resultset.close (); } Catch(Exception e) {e.printstacktrace (); }        finally        {            Try            {                if(st!=NULL) St.close (); } Catch(Exception e) {e.printstacktrace (); }            finally            {                if(conn!=NULL)                    Try{conn.close (); } Catch(Exception e) {e.printstacktrace (); }            }        }    }}

JDBC Performance Management System

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.