Java operations on Oracle databases

Source: Internet
Author: User

1. Import the required jar packages, find ojdbc14.jar and nls_charset12.jar in \ JDBC \ Lib of the Oracle client installation directory, and add these two jar packages to the project.

(A simple method is to create a new directory libs in the project, copy the jar package to the directory, right-click the JAR file, and select Add to build path)


2. Write test code

Import Java. SQL. *; public class main {string dburl = "JDBC: oracle: thin: @ Oracle Database IP: Port Number: database instance name"; string theuser = "mw_sys "; string thepw = "sys"; connection c = NULL; statement conn; resultset rs = NULL; public main () {try {class. forname ("oracle. JDBC. driver. oracledriver "). newinstance (); C = drivermanager. getconnection (dburl, theuser, thepw); Conn = C. createstatement ();} catch (exception e) {e. printstacktrace () ;}} public resultset executequery (string SQL) {rs = NULL; try {rs = conn.exe cutequery (SQL);} catch (sqlexception e) {e. printstacktrace ();} Return Rs;} public void close () {try {Conn. close (); C. close ();} catch (exception e) {e. printstacktrace () ;}} public static void main (string [] ARGs) {resultset RS; main conn = new main (); rs = conn.exe cutequery ("select * from table name"); try {While (RS. next () {system. out. println (RS. getstring ("field name");} catch (exception e) {e. printstacktrace ();}}}

The code above only lists database query operations. Other operations are similar. The red part must be modified.

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.