sql2005 JDBC Connection MSSQL Database implementation method

Source: Internet
Author: User

sql2005 JDBC Connection MSSQL Database Tutorial implementation method

Class.forName ("Com.microsoft.sqlserver.jdbc.sqlserverdriver");

url = "Jdbc:sqlserver://localhost:1433;databasename=tempdb";


First download to SQL2005JDBC driver Sqljdbc_2.0.1008.2_enu.exe (support for sql2005,2.0 after version number 1.1 sql2008)

The download is a decompression can be used, do not need to install, you can put this bag anywhere you want to put, for example, you put the bag

Under the C:Program files directory. and the path to the Sqljdbc.jar package is

C:Program filesmicrosoft SQL Server Driversqljdbc_1.2enusqljdbc.jar JDBC

You can also place the package under your Tomcat common directory, or under the class path of your newly created project.

Second, configure the Tomcat server.

Make sure you have Tomcat installed. Open the monitor Tomcat server and add the Sqljdbc.jar package path under Java classpath of the Java tab

C:Program FilesMicrosoft SQL Server The Driversqljdbc_1.2enusqljdbc.jar JDBC (two different I jar package

To be separated by a semicolon ";", restart the Tomcat server so that the Tomcat configuration is complete;

Third, configure the sql2005 server.

Configure TCP ports: Start-> All Programs->microsoft SQL Server 2005-> Configuration Tool->sql Server Configuration Manager

->sql Server 2005 Network Configuration->mssqlserver Protocol; enable "TCP/IP"; double-click "TCP/IP->"-> "Ipall"

-> the "TCP port" entry to add the default "1433". Restart the sql2005 server, which completes the configuration of the sql2005 server.

Iv. Copy and prepare documents

Find the Sqljdbc_auth.dll file in the SQLJDBC driver you downloaded, such as c:program files in the directory I unpacked, so I

The Sqljdbc_auth.dll file is

C:Program filesmicrosoft SQL Server Driversqljdbc_1.2enuauthx86sqljdbc_auth.dll JDBC

Put the found file into the C:windowssystem32 directory, this is a dynamic Run-time library, this dongdong must not be less.

Write a test file and test it. (End of article has appendix)

Remember: On the server (whether it is a Tomcat server or a sql2005 server configuration has been changed to make the changes take effect must restart the server)

If you can't fix it, you can try again. Open More services to the SQL2005 server specific operations are as follows:

1. Peripheral application Configuration:

The Microsoft SQL Server 2005-> Configuration tool->sql The server perimeter configuration-> service and the perimeter configuration of the connection->

① Select sqlexpress->database engine-> remote connection-> local and remote connections-> use TCP/IP and named pipes concurrently;

② Select SQL Server browser-> service-> startup type to "Auto"-> application-> start-> OK.

2. Modify the default logon authentication mode (because it is installed by default in Windows Authentication mode during the installation process, the SA login is prohibited
, the sa login is still disabled, even if the authentication mode is changed to SQL Server and Windows Authentication mode, so you need

To enable the sa login account):

① in the Object Explorer of SQL Server Management Studio, security-> login-> Right-click "sa"-> properties-> General->

Set the password and confirmation password for the login SA to strong password-> State-> login-> enable-> OK;

② in the Object Explorer of SQL Server Management Studio, right-click the Server-> property-> security-> Server Authentication->

Select SQL Server and Windows Authentication mode-> determine->

Package Com.wangguan;

Import java.sql.connection;
Import Java.sql.drivermanager;
Import java.sql.sqlexception;
Import java.sql.statement;


public class Testjdbc {

public static void Main (string[] args) {
Connection con = null;
Statement STA = null;

try {
Class.forName ("Com.microsoft.sqlserver.jdbc.sqlserverdriver");
String url = "Jdbc:sqlserver://127.0.1:1433;databasename=studentmanager";
con = drivermanager.getconnection (URL, "sa", "Wangguan");
STA = Con.createstatement ();
String sql = "INSERT INTO student" +
"(Stuname, Address, Stutel, age, GroupID)" +
"Values" +
"(' Crown ', ' Heilongjiang ', ' 13723984599 ', 23,2)";
int row = sta.executeupdate (SQL);
if (row = = 0) {
System.out.println ();
} else {
System.out.println ();
}
Sta.close ();
Con.close ();
catch (ClassNotFoundException e) {
E.printstacktrace ();
catch (SqlException e) {
E.printstacktrace ();
finally {
try {
if (STA!= null) {
Sta.close ();
STA = null;
}
if (con!= null) {
Con.close ();
con = null;
}
catch (SqlException e) {
E.printstacktrace ();
}
}
}

}

Download Address: Http://download.microsoft.com/download/8/b/d/8bdabae2-b6ea-41d4-b903-7916ef3690ef/sqljdbc_1.2.2323.101_enu.exe

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.