Java connection Simple instance of Oracle database

Source: Internet
Author: User

package cn.com.login.dao;import java.sql.connection;import java.sql.drivermanager;import  java.sql.preparedstatement;import java.sql.resultset;public class logindao {     public string getusername (String usercode) {    connection  con = null;    preparedstatement pre = null;     ResultSet result = null;    String userName =  "";     try {class.forname ("Oracle.jdbc.driver.OracleDriver");  // Load the Oracle driver System.out.println ("Start trying to connect to the database!") "); string url =  "jdbc:oracle:"  +  "thin:@10.10.19.19:1521:db123"; string user =  "System"; string password =  "scc123456"; Con = drivermanager.getconnection (url, user,  password); SYSTEM.OUT.PRINTLN ("Connection succeeded"); string sql =  "select username  from web01_test where usercode = ? "; Pre = con.preparestatement (SQL);p re.setstring (1, usercode); Result = pre.executequery ( );while  (Result.next ())  {username = result.getstring ("UserName");}}  catch  (exception e)  {e.printstacktrace ();}  finally {    try {    if  (result !=  NULL)  {    result.close ();    }    if  ( Pre != null)  {    pre.close ();    }     if  (Con != null)  {    con.close ();     }}  catch  (Exception e2)  {e2.printstacktrace ();}     }    return username;    }}


Java connection Simple instance of Oracle database

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.