JDBC Connection Database

Source: Internet
Author: User

A JDBC Connection database is generally divided into 3 steps:

(1) Register database driver

(2) Creating a database connection URL

(3) Get Connection Connection object

These three steps, the specific code implementation is as follows:

1 Try{2             //Load Database driver, register to drive manager3Class.forName ("Com.mysql.jdbc.Driver");4             //Database connection String5String url = "Jdbc:mysql://localhost:3306/mysqltest";6             //Database user name7String userName = "root";8             //Database Password9String PassWord = "123456";Ten             //Create a connection connection OneConnection conn =(Connection) drivermanager.getconnection (Url,username,password); A             //determine if the database connection is empty -             if(Conn! =NULL){ -                 //Output Connection Information theOut.print ("Database connection succeeded! "); -                 //To close a database connection - conn.close (); -}Else{ +                 //Output connection error message -OUT.PRINTLN ("Database connection failed! "); +             } A}Catch(ClassNotFoundException e) { at e.printstacktrace (); -}
View Code

JDBC Connection Database

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.