JDBC connection to Oracle Database

Source: Internet
Author: User
Import Java. SQL. connection; import Java. SQL. drivermanager; import Java. SQL. preparedstatement; import Java. SQL. resultset; import Java. SQL. sqlexception;/*** JDBC connection to Oracle Database ** @ author zhanqi **/public class Oracle {Private Static string driver = "oracle. JDBC. driver. oracledriver "; Private Static string url =" JDBC: oracle: thin: @ 127.0.0.1: 1521: orcl "; public static void main (string [] ARGs) {connectio N Ct = NULL; preparedstatement PS = NULL; resultset rs = NULL; try {// load the driver class. forname (driver); // obtain the connection Ct = drivermanager. getconnection (URL, "Scott", "Scott"); // obtain the pre-compiled SQL statement object PS = CT. preparestatement ("select count (*) from EMP"); // obtain the result set rs = ps.exe cutequery (); // cyclically retrieve the record while (RS. next () {system. out. println (RS. getint (1) ;}} catch (exception e) {e. printstacktrace ();} finally {// off Close resource try {If (RS! = NULL) {Rs. Close () ;}if (PS! = NULL) {ps. Close () ;}if (CT! = NULL) {CT. Close () ;}} catch (sqlexception e) {e. printstacktrace ();}}}}

Appendix:

  • Oracle JDBC driver: Download
  • Oracle JDBC driver: Oracle Installation Directory: F: \ app \ zhanqi \ product \ 11.2.0 \ dbhome_1 \ JDBC \ Lib
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.