JAVA and database connection method (2)

Source: Internet
Author: User

Now we will introduce the second method to connect with the corresponding driver provided by the related manufacturer.
This method is to directly use the driver created using the dedicated network protocol provided by the database vendor, through which jdbc api calls can be directly converted to direct network calls. This call method has good performance and is also the simplest method in practice. Because it requires installation of other libraries or middleware. Almost all database vendors provide such JDBC drivers for their databases, and these drivers can also be obtained from third-party vendors.
Visit http://industry.java.sun.com/products/jdbc/drivers/to view all drivers. Result:
Application --- jdbc api --- driver --- Data Source
First install the JDBC driver. The SP2 version is recommended and can be downloaded from the Microsoft website.
Http://www.microsoft.com/downloads/details.aspx? FamilyID = 9f1874b6-f8e1-4bd6-947c-0fc5bf05bf71 & DisplayLang = en download the following SETUP. EXE
This driver must work with SQL SERVER2000 SP3A and the corresponding download URL is
Http://www.microsoft.com/china/ SQL /downloads/sp3.asp download chs_sql2ksp3.exe
If you use the java sdk to compile and run the SDK directly, you need to set the environment variables and set the LIB files in the installed JDBC driver to the environment variables:
Classpath:
D: program filesMicrosoft SQL Serverjdbclibmsbase. jar;
D: program filesMicrosoft SQL Serverjdbclibmssqlserver. jar;
D: program filesMicrosoft SQL Serverjdbclibmsutil. jar;
After installation, Microsoft's driver can be used to connect to the database. The corresponding code is basically the same as the previous one:
Import java. SQL .*;
Import java. io .*;
Public class DBColumn {
Public static void main (String [] args ){
Connection con = null;
Statement sm = null;
String command = null;
ResultSet rs = null;
String tableName = null;
String cName = null;
String result = null;
BufferedReader input = new BufferedReader (new InputStreamReader (System. in ));
Try
{
Class. forName ("com. microsoft. jdbc. sqlserver. SQLServerDriver ");
System. out. println ("driver loaded ");
// The SQL server login method must be the SQL SERVER password login authentication method
Con = DriverManager. getConnection ("jdbc: microsoft: sqlserver: // SERVERNAME: 1433", "USER", "PASSWORD ");

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.