Mysql,oracle,sqlserver using JDBC to connect to a database summary

Source: Internet
Author: User

The JDBC connection data is a key point of javaweb development, and today we summarize and deepen our memory.

The JDBC Connection database is divided into three steps:

1: Load Driver

Need to download the respective drive jar package, you can go to the Internet search.

Template: load driver: Class.forName (Driverclass);

Different database connections are not the same way, I would like to summarize:

  MySQL: com.mysql.jdbc.Driver

  Oracle: Oracle.jdbc.OracleDriver

  SQL Server: com.microsoft.sqlserver.jdbc.SQLServerDriver

2: Get a data connection

  mysql: Connection con =drivermanager.getconnection ("jdbc:mysql://127.0.0.1:3306/ database name " ," Database user "," Database Password ");

  SQL Server: Connection con = drivermanager.getconnection ("Jdbc:sqlserver://127.0.0.1:1433;databasename= Database name "," Database User "," Database Password ");

  Oracle: Connection con = drivermanager.getconnection ("jdbc:oracle:thin:@127.0.0.1:1521: Database Name", "Database User", " Database Password ");

3: Create a statement object

  Conn.creatstatement ();

Then you can do the SQL operation, remember to use the end to close!

Mysql,oracle,sqlserver using JDBC to connect to a database summary

Related Article

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.