Manipulating a database using the Jdbc-odbc Bridge connection

Source: Internet
Author: User
Tags odbc create database

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.)

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.