Database Operations Classes

Source: Internet
Author: User

For JDBC Operations database steps:

1. Import the driver package

2. Load driver (for MySQL database, Class.forName ("com.mysql.jdbc.driver"), for SQL Serverl database, class.forname (" Com.microsoft.sqlserver.jdbc.SQLServerDriver"))

Do not know the driving class, you can find the jar package to find similar "Driver" words, can be found.

3. Get Connection

4. Obtain Statement or preparedstatement, execute the executeupdate () and executeQuery () methods, Returns the result set resultset or affects the number of rows int.

5. Close the resultset, close the statement, close the connection.

The 2nd step is enough, 3rd. 4.5-Step loop operation, so do not place the third step in the constructor method until the operation class is instantiated only once.

Reference Example:

Example 1:

private static final String dburl= "jdbc:mysql://localhost:3306/test?user=root&password=admin& Useunicode=true&characterencoding=utf-8";

This.conn=drivermanager.getconnection (Dburl);

Example 2:

private static final String dburl= "jdbc:mysql://localhost:3306/test?useunicode=true&characterencoding= Utf-8";
private static final String user= "root";
private static final String password= "admin";

This.conn=drivermanager.getconnection (dburl, user, password);

Example 3:

private static final String dburl= "Jdbc:sqlserver://localhost:1433;databasename=db_test;user=sa; password=123456";

Database Operations Classes

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.