Use java datasource for oracle jdbc connection

Source: Internet
Author: User

Document1. Download the oracle jdbc package, which is usually a jar package or zip package on the official oracle website.

Http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html

2. Install the oracle jdbc package and add these packages to your project to import the corresponding oracle class.

3. Sample Code:

Reference content is as follows:

Import java. SQL. Connection;
Import java. SQL. PreparedStatement;
Import java. SQL. ResultSet;
Import java. SQL. SQLException;
Import java. util. Properties;
Import oracle. jdbc. pool. OracleDataSource;

Public class Main {
Public static void main (String [] args ){
Try {
OracleDataSource ods = new OracleDataSource ();
Ods. setDriverType ("thin"); // type of driver
Ods. setNetworkProtocol ("tcp"); // tcp is the default anyway
Ods. setServerName ("127.0.0.1"); // database server name
Ods. setDatabaseName ("TEST"); // Oracle SID
Ods. setPortNumber (1521); // listener port number
Ods. setUser ("user"); // username
Ods. setPassword ("123456"); // password

Connection conn = ods. getConnection ();
PreparedStatement ps = conn. prepareStatement ("select * from pipe ");
ResultSet rsw.ps.exe cuteQuery ();
While (rs. next ())
{
String source = rs. getString ("SOURCE_ID ");
System. out. println (source );
}
System. in. read ();
}
Catch (Exception e)
{
System. out. println (e. getMessage ());
}


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.