(SQL Sever 2008 is the same as the SQL Sever 2005 load JDBC driver )
First, load-driven text tutorial
1, prepare the relevant software (except Eclipse, open source software can be downloaded from the website)
<1>. Microsoft SQL Server 2005 Express Edition
:Http://download.microsoft.com/download/0/9/0/09020fab-d2c3-4a8c-b9e0-db53a7a30ae8/SQLEXPR_CHS.EXE
<2>. SQL Server Management Studio (SQL sever2005/2008 database management system software)
:http://www.microsoft.com/downloads/details.aspx?displaylang=zh-cn&FamilyID= C243a5ae-4bd1-4e3d-94b8-5a0f62bf7796#filelist
<3>. SQL Server 2005 Driver for JDBC (SQL sever2005/2008 version of JDBC driver)
: Http://download.microsoft.com/download/8/B/D/8BDABAE2-B6EA-41D4-B903-7916EF3690EF/sqljdbc_1.2.2323.101_enu.exe
The first two belong to the database software, the normal installation can (note database login do not use Windows authentication)
2. Installing SQL Server 2005 Driver for JDBC driver
(premise Eclipse, SQL Server Management studio Download installation completed)
<1> extract JDBC to any location, such as unzip to C-disk program files, and find the Sqljdbc.jar file in the installation directory, get the path to start configuring environment variables
Append C:\Program Files\Microsoft SQL Server2005 JDBC Driver\sqljdbc_1.2\enu\sqljdbc.jar after environment variable classpath
<2> set up SQLExpress server:
A. Opening protocol-TCP/IP for SQL Server Configuration Manager-SQLExpress
B. Right-click Start TCP/IP
C. Double-click the Enter property to set the TCP port in IP all to 1433
D. Restarting a sqlexpress server in a SQL Server 2005 service
E. Shutting down SQL Server Configuration Manager
<3> Open the newly installed SQL server Management Studio, connect the SQLExpress server, create a new database, name the sample
<4> Open Eclipse
A. Java project, Java, New project, named JDBC
B. Select Eclipse-> window, Preferences->java->installed JRE Edit the installed JDK, find directory add Sqljdbc.jar
C. Right-click on test in the Catalog window, choose Build path->configure Build path ..., add extension jar file, add Sqljdbc.jar to it
<5> writing Java code to test the JDBC connection to the SQL Server database
(If SQL Sever 2008 has created a login account to access the database Zxj))
/ * To test the JDBC connection to the SQL Server database * /
import java.sql.*;
Public class JDBC {
Public static void Main (string[] SRG) {
String drivername = "com.microsoft.sqlserver.jdbc.SQLServerDriver";//load JDBC driver
String dburl = "jdbc:sqlserver://localhost:1433; Databasename=java "; Connect server and Database sample
String userName = "ZXJ";//Default User name
String userpwd = "ZXJ";//Password
Connection dbconn;
try {
Class.forName (drivername);
dbconn = drivermanager.getconnection (Dburl, UserName, userpwd);
System.out.println ("Connection successful!");//If the connection succeeds console output Connection successful!
} catch (Exception e) {
e.printstacktrace ();
}
}
}
Second, load-driven graphics tutorial
Java Connect to SQL Sever 2008_java Basic Learning