SQL2000 installation and Setup of Java JDBC driver

Source: Internet
Author: User

1. First, remember to patch SQL2000 with SP3 or above (SP4 is recommended)
2. Install SQL Server 2000 driver for JDBC Service Pack 3
: Http://www.microsoft.com/downloads/details.aspx? Familyid = 07287b11-0502-461a-b138-2aa54bfdc03a & displaylang = en

 

3. After installing SQL Server 2000 driver for JDBC Service Pack 3, it is installed in c: \ Program Files \ Microsoft SQL Server 2000 driver for JDBC by default, in C: \ Program Files \ Microsoft SQL Server 2000 driver for JDBC \ Lib contains three jar files:
Msbase. jar, MSSQLServer. jar, msutil. jar, remember to copy these three files to the JRE under your installed JDK. Here I will describe my installation Configuration:
My JDK is jdk1.5.0 _ 09, which is installed on:
In C: \ Program Files \ Java, there are two folders under the c: \ Program Files \ Java directory:
Jdk1.5.0 _ 09 directory and jre1.5.0 _ 09 directory,
The Three jar files mentioned above must be copied to the ext directory under the lib directory under the JRE directory under the jdk1.5.0 _ 09 directory. The complete path here is:
C: \ Program Files \ Java \ jdk1.5.0 _ 09 \ JRE \ Lib \ ext

 

 

4. Set classpath and add the Three jar files.

5. Set SQL2000 to mixed logon mode (Windows and SQL)
 

 

Bytes -----------------------------------------------------------------------------------------------------------

Call example JavaCodeString 1

Bytes ----------------------------------------------------------------------------------------------------------

 

Import java. SQL. sqlexception;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. preparedstatement;
Import java. SQL. statement;
Import java. SQL. resultset;
// Import java .*;

String 4

 

Class courseappl {

Private connection conn;
Private string URL;
Private string servername;
Private string portnumber;
Private string databasename;
Private string username;
Private string password;
Private string SQL;

Courseappl (){

Url = "JDBC: Microsoft: sqlserver ://";
Servername = "localhost ";
Portnumber = "1433 ";
Databasename = "test ";
Username = "sa ";
Password = "";
}

Private string getconnectionurl (){

 


// System. Out. println (URL + servername + ":"
// + Portnumber + "; databasename ="
// + Databasename + ";");
Return URL + servername + ":"
+ Portnumber + "; databasename ="
+ Databasename + ";";
}

Private connection getconnection (){

Try {

System. Out. println (getconnectionurl (); string 4
Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver ");
// Class. forname ("com. Microsoft. sqlserver. JDBC. sqlserverdrive ");
Conn =
Drivermanager. getconnection (getconnectionurl (), username, password );

If (Conn! = NULL ){

System. Out. println ("database connection successful! ");
}

 

} Catch (exception CE ){

Ce. printstacktrace ();
System. Out. println ("getconnection () Internal Error Tracking:" +
Ce. getmessage ());
}

Return conn;
}

Public void display (){

Try {

Conn = getconnection ();

Preparedstatement pstmt =
Conn. preparestatement ("Update friends set" +
"Salary =? Where name like? ");
Pstmt. setint (1,10000 );
Pstmt. setstring (2, "Li Si ");
Pstmt.exe cuteupdate ();
System. Out. println ("Li Si's record has been updated !! ");

Statement stmt = conn. createstatement ();
Resultset rs = stmt.exe cutequery ("select * from friends ");
If (! Rs. Next ()){
System. Out. println ("empty table, no data !! ");
} Else {


System. Out. Print (Rs. getstring (1) + "\ t ");
System. Out. Print (Rs. getstring (2) + "\ t ");
System. Out. Print (Rs. getint (3) + "\ t"); string 9
System. Out. Print (Rs. getdate (4) + "\ t ");
System. Out. Print (Rs. getint (5) + "\ t ");
System. Out. println ();

While (Rs. Next ()){

System. Out. Print (Rs. getstring (1) + "\ t ");
System. Out. Print (Rs. getstring (2) + "\ t"); string 6
System. Out. Print (Rs. getint (3) + "\ t ");
System. Out. Print (Rs. getdate (4) + "\ t ");
System. Out. Print (Rs. getint (5) + "\ t ");
System. Out. println ();
}
}

} Catch (sqlexception CE ){

System. Out. println (CE );
}
}


Public static void main (string [] ARGs ){

Courseappl retobj = new courseappl ();
Retobj. getconnection ();
Retobj. Display ();
}
}

 

Http://blog.csdn.net/allen_l/archive/2007/01/25/1493155.aspx

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.