JAVA JDBC Connection Oracle Test code

Source: Internet
Author: User

package com.ist.common.util;import java.sql.*;import javax.naming.context;import  Javax.naming.initialcontext;import javax.naming.namingexception;public class jdbcoracletest  {    //ORCL is the database name in the Oracle database, and localhost represents the Oracle database that connects to the native           //1521 is the port number of the connection          private static  string url= "JDBC:ORACLE:THIN:@192.168.99.98:1521:ORCL";         //system user name for landing Oracle database          private static  String user= "nms09";         //manager password for user name System           private static string password= "Nms09";         public static Connection conn;         public static preparedstatement ps;        public static  Resultset rs;        public static statement st  ;        //How to connect a database           public void getconnection () {             try {                 //initializing the driver package                   class.forname ("Oracle.jdbc.driver.OracleDriver");                 //assigning values to conn based on database connection characters, names, and Passwords                   conn=drivermanager.getconnection (url,  User, password);                              } catch  (exception e)  {                 // todo: handle  exception                  e.printstacktrace ();             }         }         // Test whether the connection to the Oracle database is successful           public static void  main (String[] args)  {         jdbcoracletest  basedao=new jdbcoracletest ();             basedao.getconnection ();  &nbsP;          if (conn==null) {                 SYSTEM.OUT.PRINTLN ("Connection to Oracle database failed! ");            }else{                 SYSTEM.OUT.PRINTLN ("Connection to Oracle database was successful! ");            }          }   }


JAVA JDBC Connection Oracle Test code

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.