Several ways JDBC connects to SQL Server

Source: Internet
Author: User

First: Jdbc-odbc database connection Bridge (need to configure ODBC data source, no download driver required)
class.forname ("Sun.jdbc.odbc.JdbcOdbcDriver");
con=drivermanager.getconnection ("JDBC:ODBC: Data Source Name", "username", "password");

Second: Take advantage of Microsoft-supplied drivers (XP users need to hit SP3 patches and need to download drivers)
class.forname ("Com.microsoft.jdbc.sqlserver.SQLServerDriver");
con=drivermanager.getconnection ("jdbc:microsoft:sqlserver://localhost:1433;databasename= database name", "username", "password");

Third: Using drivers provided by third parties (download driver required)
class.forname ("Net.sourceforge.jtds.jdbc.Driver");
con=drivermanager.getconnection ("jdbc:jtds:sqlserver://localhost:1433/database name; user= user name; password= password");

Fourth: Configure the data source under struts (in fact this is not a type with the top)
<data-sources>
<data-source key= "name of data source in struts" type= "Org.apache.commons.dbcp.BasicDataSource" >
<set-property property= "Driverclassname" value= "Sun.jdbc.odbc.JdbcOdbcDriver"/>
<set-property property= "url" value= "JDBC:ODBC: Data source"/>
<set-property property= "username" value= "username"/>
<set-property property= "password" value= "password"/>
</data-source>
</data-sources>

Related Article

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.