Connect to the database using JDBC and JDBC-ODBC drivers

Source: Internet
Author: User

 

1,
JDBC-ODBC driver to access sqlserver2008 Database

Principle of JDBC-ODBC Access Database

JSPProgram--> JBDC-ODBC driver --> ODBC driver ---> database so be sure to install ODBC driver on the Java Server when using JDBC-ODBC access


To use the JDBC-ODBC driver, you must first load the driver class using the forname static method of the class to load


Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver"); // load the JDBC-ODBC driver
Drivermanager. connection ("JDBC: ODBC: datasource"); // datasource is the data source. We do not need to add an account or password because we have used the SA user name SA user as the highest user When configuring the ODBC data source.

 

 

 

2. The class. forname Method for JDBC access throws the classnotfoundexception exception. Other SQL operations throw the sqlexception exception.

Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver"); // load the JDBC driver

For different database connection parameters for connection to sqlserver2008

Drivermanager. connection ("JDBC: Microsoft: sqlserver // localhost \ sqlexpress: 1433; databasename = database name", "sa", "password"); // The account password is required to connect to the sql2008 Parameter

 

 

The default SQL database instance name is sqlexpress.

The instance is also the name of the database server. The SA in sql2008 is the highest user. It is best not to use the default Instance name when creating a database.

In the query, select @ servicename as Shili can get the server instance name

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.