How to load the database driver and the JDBC process

Source: Internet
Author: User

Load Drive method1.class.forname ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");2. Drivermanager.registerdriver (New Com.mysql.jdbc.Driver ());3.system.setproperty ("Jdbc.drivers", "Com.mysql.jdbc.Driver"); JDBC Process:
    1. Load the drive DriverManager. Registerdriver (Driver Driver)
    2. Get connection Connection conn = drivermanager.getconnection (Url,user,pass);
    3. Create Statement Statement st = Conn.createstatement () by connection;
    4. Parse SQL get result set ResultSet rs = st.excutequery (SQL);
    5. Traverse result set, get Data Rs.getobject (XX)
    6. Freeing resources, closing connections
  • 1. Load the JDBC driver:
  • before connecting to the database, first load the driver of the database you want to connect to the JVM (Java Virtual machine),
  • This is achieved through the static method forname (String className) of the Java.lang.Class class.
  • 2 Creating a connection to a database
  • To connect to a database, you need to request and obtain a connection object from Java.sql.DriverManager.
  • The object represents a connection to a database.
  • ? Using the DriverManager getconnectin (string URL, string username,
  • String password) method to pass in the path to the specified database to be connected, the user name of the database, and
  • Password to get it.

Methods for loading database drivers and the process of JDBC

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.