JSP+JDBC (thin mode) connect Oracle

Source: Internet
Author: User
Tags connect zip root directory

There are generally 2 ways to connect to Oracle in a JSP:

1, Oracle jdbc Oci8 Way

2, Oracle jdbc Thin way

I prefer the 2nd, because the Web publisher and the database server are generally not on the same computer, and when using thin connection, the Web server side does not need to install Oracle clients.

Before we start the code, we'll configure the environment properly. From the database server where Oracle is installed, locate the Oracle installation directory, and then copy the Jdbc\lib\classes12.jar files from that directory to a directory on the Web Publisher. Suppose you put it directly in the C:\ root directory, and then add the path to the ' System-advanced-environment variable ' value in the variable named ' CLASSPATH ', such as: D:\Program files\sqllib\java\db2java.zip;d:\ Program Files\sqllib\java\runtime.zip;c:classes12.jar; So that Java can find this package.

After configuring the environment, we began to write code. About the database connection code, should write a special connection class to call, no need to think of some articles on the network like that, write directly to the JSP code.

The code for the connection is simple

private Connection newConnection(String user,String password) {
Connection con = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection (“jdbc:oracle:thin:@192.168.96.1:1521:oracle9i”,user,password);
}
catch (SQLException e) {
return null;
}
return con;
}

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.