1 PackageUtil;2 3 Importjava.sql.Connection;4 ImportJava.sql.DriverManager;5 ImportJava.sql.ResultSet;6 Importjava.sql.SQLException;7 Importjava.sql.Statement;8 9 ImportOrg.omg.CORBA.PRIVATE_MEMBER;Ten One Public classDbutil { A Public Static voidMain (String args[])throwsException { - FinalString url = "Jdbc:sqlserver://localhost:1433;databasename=studb"; - the Try { - //1. Registration Driver - //class.forname ("Com.mysql.jdbc.Driver"); -Class.forName ("Com.microsoft.sqlserver.jdbc.SQLServerDriver"); + //2. Get Data Link -Connection conn = drivermanager.getconnection (URL, "sa", "123456"); + AStatement stmt =conn.createstatement (); atResultSet rs = stmt.executequery ("SELECT * from Stuinfotable"); - - while(Rs.next ()) { -System.out.println (Rs.getint (1) + "" + rs.getstring (2) + "" +rs.getstring (3)); - } -}Catch(ClassNotFoundException e) { in //TODO auto-generated Catch block - e.printstacktrace (); to } + } -}
Java Link SQL Server database