The steps to manipulate a database using the Jdbc-odbc bridge are as follows:
1. Configure the data source
Select control Panel → admin tools → data source, pop-up diagram dialog box
Click Add, select SQL SERVER
Click Finish to eject the following dialog box
(If you are connecting to a local server, fill it out locally or.)
Click Next
Click Next
The default connected database is master, which is changed to the experimental requirements database.
Click Next, pop Up the following dialog box, do not make any changes, directly click to complete.
Select test Data source
Configure the data source to complete.
2, in the program to connect the data source
The first step: Load driver (the role is to put the required driver into memory)
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver")
Step two: Get the connection (specify which data source to connect to), and if you are configuring the data source to choose Windows NT Authentication, you do not need to write a username and password
Connection ct=drivermanager.getconnection ("Jdbc:odbc:simpledb") is written after the data source if it has a username and password.
Step three: Create statement or PreparedStatement
Statement function: Mainly used to send SQL statements to the database.
The difference between statement and PreparedStatement:
(1) Direct use of statement, the driver will not normally handle the driver, but directly to the database, the use of PreparedStatement to form a precompiled process, and the statement do character set conversion.
So, there are two benefits, for statements that are repeated repeatedly, using preparedstatement is more efficient and, in this case, more appropriate for a batch query. In addition, can also be a better solution to the system localization problems.
(2) PreparedStatement can also effectively prevent the injection of dangerous characters.
Step Fourth: Execute (CRUD, create DATABASE, delete database, etc.)