Oracle-based JDBC connection tutorial

Source: Internet
Author: User
The Oracle-based Jdbc connection technology requires a third-party jar package. You can find the corresponding jar package in the sub-package jdbc under the Oracle Installation Package, select the corresponding jar package based on the oracle version. Here I use ojdbc14.jar. First, see a class to connect to the database. In actual development, this class is used as a tool class and put into the util package.

The Oracle-based Jdbc connection technology requires a third-party jar package. You can find the corresponding jar package in the sub-package jdbc under the Oracle Installation Package, select the corresponding jar package based on the oracle version. Here I use ojdbc14.jar. First, see a class to connect to the database. In actual development, this class is used as a tool class and put into the util package.

The Oracle-based Jdbc connection technology requires a third-party jar package. You can find the corresponding jar package in the sub-package jdbc under the Oracle Installation Package, select the corresponding jar package based on the oracle version. Here I use ojdbc14.jar.

First, see a class for database connection. In actual development, this class is used as a tool class, put it in the util package, and name it JdbcUtil.


Package util; import java. SQL. connection; import java. SQL. driverManager; import java. SQL. SQLException; public class JdbcUtil {public static Connection getConnection () {Connection conn = null; String url = "jdbc: oracle: thin: @ localhost: 1521: orcl "; // urlString password = "1234"; // database password String user = "haha"; // try {Class. forName ("oracle. jdbc. oracleDriver "); // reflection mechanism, loading class driver conn = DriverManager. getConnection (url, user, password); // catch (ClassNotFoundException e) {e. printStackTrace ();} catch (SQLException e) {e. printStackTrace () ;}return conn ;}}

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.