JDBC connection to Oracle

Source: Internet
Author: User
The JDBC driver can be found in c: \ oracle \ ora92 \ JDBC \ Lib \ ojdbc14.jar.

Package JDBC;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. resultset;
Import java. SQL. sqlexception;
Import java. SQL. statement;
Public class Test2
{
Private Static connection con = NULL;
Public Test2 ()
{
}
Public static final connection getcon ()
{
String forname = "oracle. JDBC. Driver. oracledriver ";
String url = "JDBC: oracle: thin: @ 192.168.10.23: 1521: Test ";
String user = "system ";
String Password = "headfree ";

Try
{
Class. forname (forname). newinstance ();
Con = drivermanager. getconnection (URL, user, password );
}
Catch (exception E)
{
E. printstacktrace ();
}
Return con;
}
Public static final void close (resultset, object OBJ, connection)
{
If (resultset! = NULL)
Try
{
Resultset. Close ();
Resultset = NULL;
}
Catch (sqlexception)
{
}

If (OBJ! = NULL & (OBJ instanceof statement ))
Try
{
(Statement) OBJ). Close ();
OBJ = NULL;
}
Catch (sqlexception sqlexception1)
{

}
If (connection! = NULL)
Try
{
Connection. Close ();
Connection = NULL;
}
Catch (sqlexception sqlexception2)
{
}
}
Public static void main (string ARGs [])
{
Connection conn = test2.getcon ();
If (Conn! = NULL)
{
System. Out. println ("successful ");
}
JDBC. test2.close (null, null, 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.