Package zmsjdbc; import java.sql. *; public class sqlserver1 {
Private string url = "JDBC: Microsoft: SQL Server: // localhost: 1433; DatabaseName = CATV"; private string user = "sa"; private string pwd = ""; public connection getcon () {connection con; Load the driver class.forname ("com.microsoft.jdbc.sqlser.sqlserverdriver). NewInstance (); // Create a connection Con = DriverManager.getConnection (URL, User, PWD); Return Con;} catch (ClassNotNotNotNDException E) {System.out.Println ("Load Driver Error");} catch (sqlexception e) {system.out.println (E.GetMessage ());} catch (exception e) {system.out.println ("appears A big mistake ");
Return NULL;
Public ResultSet EXECUTESQL (String Sqlstr) {Connection Conn; Statement Stmt;
Try {conn = getCon (); stmt = conn.createstatement (); resultset = stmt.executeQuery (SQLSTR);
Return RS;} catch (sqlexception e) {system.out.print ("Errors when getting data set");} return null;}
public static void main ResultSet rs1 (String [] args) {; sqlserver1 sql1 = new sqlserver1 (); rs1 = sql1.executeSql ( "select ui_id, ui_name from userinfo"); try {while (rs1.next ()) {System .out.println ("UI_ID") "Name: rs1.getstring (" ui_name "));}}}} Catch (Exception E) {System.out.Println (E.getMessage ()); }}} / * 11:08 2005-2-24 -by beyond 1: For SQLServer must download SQL Server driver http://download/3/0/F/30FF65D3-A84B-4B8A-A570- 27366B2271D8 / setup.exe then copy the msbase.jar mssqlser.jar msutil.jar to d: /jbuilder9/jdk1.4/lib/jre 2: If an error occurs: java.sql.sqlexception: [Microsoft] [SQLServer 2000 Driver For JDBC] Error Establishing Socket. Description SQlerver port number is not "" "" "" "" "" "" " NetStat-a, for example: string url = "JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = ZMSTV"; Description What you are using 1433 Enter netstat -a -n under CMD should not see: TCP 127.0.0.1 : 1433 0.0.0.0:0 Listening * /
Package zmsjdbc; import java.sql. *; public class sqlserver1 {
Private string url = "JDBC: Microsoft: SQL Server: // localhost: 1433; DatabaseName = CATV"; private string user = "sa"; private string pwd = ""; public connection getcon () {connection con; Load the driver class.forname ("com.microsoft.jdbc.sqlser.sqlserverdriver). NewInstance (); // Create a connection Con = DriverManager.getConnection (URL, User, PWD); Return Con;} catch (ClassNotNotNotNDException E) {System.out.Println ("Load Driver Error");} catch (sqlexception e) {system.out.println (E.GetMessage ());} catch (exception e) {system.out.println ("appears A big mistake ");} return null;}
Public ResultSet EXECUTESQL (String Sqlstr) {Connection Conn; Statement Stmt;
Try {conn = getCon (); stmt = conn.createstatement (); resultset = stmt.executeQuery (SQLSTR);
Return RS;} catch (sqlexception e) {system.out.print ("Errors when getting data set");} return null;}
public static void main ResultSet rs1 (String [] args) {; sqlserver1 sql1 = new sqlserver1 (); rs1 = sql1.executeSql ( "select ui_id, ui_name from userinfo"); try {while (rs1.next ()) {System .out.println ("UI_ID") "Name: rs1.getstring (" ui_name "));}}}} Catch (Exception E) {System.out.Println (E.getMessage ()); }}} / * 11:08 2005-2-24 -by beyond 1: For SQLServer must download SQL Server driver http://download/3/0/F/30FF65D3-A84B-4B8A-A570- 27366B2271D8 / setup.exe then copy the msbase.jar mssqlser.jar msutil.jar to d: /jbuilder9/jdk1.4/lib/jre 2: If an error occurs: java.sql.sqlexception: [Microsoft] [SQLServer 2000 Driver For JDBC] Error Establishing Socket. Description SQlerver port number is not "" "" "" "" "" "" " NetStat-a, for example: string url = "JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = ZMSTV"; Description What you are using 1433 Enter netstat -a -n under CMD should not see: TCP 127.0.0.1 : 1433 0.0.0.0:0 Listening * /