Eclipse-sql Server 2008 Connections

Source: Internet
Author: User

1  PackageAA;2 ImportJava.sql.*;3  Public classGold {4      Public Static voidMain (string[] args) {5String jdriver= "Com.microsoft.sqlserver.jdbc.SQLServerDriver";//SQL Database Engine6String connectdb= "JDBC:SQLSERVER://127.0.0.1:1433;DATABASENAME=JXGL";//Data Source7           8           Try9           {TenClass.forName (Jdriver);//loads the database engine and returns the class for the given string name One}Catch(classnotfoundexception e) A           { -            //e.printstacktrace (); -System.out.println ("Failed to load Database engine"); theSystem.exit (0); -           }      -SYSTEM.OUT.PRINTLN ("Database-driven Success"); -            +           Try -           { +String user= "SA"; AString password= "123456"; atConnection con=drivermanager.getconnection (Connectdb,user,password);//Connecting database Objects -SYSTEM.OUT.PRINTLN ("Connection database succeeded"); -Statement stmt=con.createstatement ();//To create a SQL command object -             -            //Create a table -System.out.println ("Start creating table"); inString query= "CREATE Table TABLE1 (ID NCHAR (2), NAME NCHAR (10))";//To create a table SQL statement -Stmt.executeupdate (query);//Execute SQL Command object toSYSTEM.OUT.PRINTLN ("Table creation succeeded"); +                -            //input Data theSystem.out.println ("Start inserting data"); *String a1= "INSERT into TABLE1 VALUES (' 1 ', ' Asahi Brothers ')";//Insert Data SQL statement $String a2= "INSERT into TABLE1 VALUES (' 2 ', ' viagra ')";Panax NotoginsengString a3= "INSERT into TABLE1 VALUES (' 3 ', ' brother Zhang ')"; -Stmt.executeupdate (A1);//Execute SQL Command object the Stmt.executeupdate (A2);  + Stmt.executeupdate (A3); ASystem.out.println ("Insert data Success"); the             +            //reading Data -System.out.println ("Start reading data"); $ResultSet rs=stmt.executequery ("SELECT * from TABLE1");//return SQL statement query result set (collection) $            //loop out each record -             while(Rs.next ()) -            { the             //Output each field -System.out.println (rs.getstring ("ID") + "\ T" +rs.getstring ("NAME")));Wuyi            } theSYSTEM.OUT.PRINTLN ("Read Complete"); -             Wu            //Close Connection -Stmt.close ();//Close Command object connections AboutCon.close ();//To close a database connection $           } -           Catch(SQLException e) -           { - e.printstacktrace (); A            //System.out.println ("Database connection Error"); +System.exit (0); the           } -          } $}

Eclipse-sql Server 2008 Connection (RPM)

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.