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