Connecting to Oracle database in Java using TNSNAMES.ora
I have a program that can connect to both MSSQL and Oracle databases. It works fine when a user has defined an odbc connection, however if the user only has a tnsnames.ora, I don't know how to code the program in Java to connect to the database. I can't hard-code the server name because I don't know the database up front - I need to be able to read tnsnames.ora to get the information instead. How can I get this information? So far, the object OracleDataSource seems to be getting me the closest, however I am still failing to connect.
In 10.2, JDBC-Thin supports TNSNAMES entries lookup in tnsnames.ora, resulting in a much simplified and driver type independent Oracle Net descriptor. You must set the system property oracle.net.tns_admin to the directory that contains your tnsnames.ora file.
See the Oracle JDBC 10.2 doc.
Here is a code fragment from my book (see my blog below)
java -Doracle.net.tns_admin=$ORACLE_HOME/network/admin
or:
System.setProperty("oracle.net.tns_admin", "c:\oracle\net\admin");
OracleDataSource ods = new OracleDataSource();
ods.setTNSEntryName("tns_alias");
ods.setUser("scott");
ods.setPassword("tiger");
ods.setDriverType("thin");
Connection conn = ods.getConnection();
Kuassi - blog http://db360.blogspot.com/
Similar Messages
-
How Connect to oracle database with java
i have trouble with my program
i use oracle 8i to my database and java for interface
this mycode :
import java.sql.*;
class TestThinApp {
public static void main (String args[])
throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
// or you can use:
// DriverManager.registerDriver(
// new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection(
"jdbc:oracle:thin:@dssw2k01:1521:orcl","scott","tiger");
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(
"select 'Hello Thin driver tester '||USER||'!' result from dual");
while(rset.next())
System.out.println(rset.getString(1));
rset.close();
stmt.close();
conn.close();
i have trouble , becouse i can connect my database with java (JDK)
if any one can help me pls?
arifPLEASE .... Ask in an Oracle Java forum.
And read the documentaiton. There is a whole document devoted to doing that. http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/toc.htm has examples.
PLEASE ... do not ask product questions in a forum which clearly has a title saying it is devoted to assisting with download problems. -
Error in connecting Oracle Database from JAVA application!!!
Hi,
I am trying to connect to the Oracle11g database server from the client machine using JAVA eclipse. I have installed the oracle client in the client machine. Once i try to execute the below code it was throwing below error:
public class Dbconnect {
public static void main (String[] args)throws Exception {
try {
Class.forName ("oracle.jdbc.driver.OracleDriver");
String connectString = "jdbc:oracle:thin:@<IP Address>:1521:orcl";
OracleDriver drivers = new OracleDriver();
System.out.println(drivers);
Connection connection = null;
connection = (OracleConnection)DriverManager.getConnection(connectString,"ADMIN", "admin");
System.out.println(connection);
System.out.println("Connected to the database");
Error:
java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DBConnect.main(DBConnect.java:15)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:237)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
... 7 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:141)
at oracle.net.nt.ConnOption.connect(ConnOption.java:123)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:337)
... 12 more
I am unable to connect using sqlplus as well ORA-12560: TNS:protocol adapter error
Please advise me on how to resolve this issue..
ThanksPrabhu wrote:
We are not able to connect from SQLplus as we.. If i issue this command in Sqlplus from client machine 'sqlplus admin/admin@'(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=<Ip Adddress>)(PORT=1521)))(CONNECT_DATA=(SID=orcl)))'' it was throwing the below error.
Error: ORA-12541: TNS:no listener
Do i need add get any config details in the client machine..
Could please tell me what is the general procedure to access the DB server from client machine..on DB Server issue following OS commands
lsnrctl start
lsnrctl status
lsnrctl service
COPT commands & results, then PASTE all back here -
How to connect oracle database with JAVA
how to connect oracle database with JAVA....
using j2sdk and Jcreator . which connector to use .. what are the code for that ..PLEASE .... Ask in an Oracle Java forum.
And read the documentaiton. There is a whole document devoted to doing that. http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/toc.htm has examples.
PLEASE ... do not ask product questions in a forum which clearly has a title saying it is devoted to assisting with download problems. -
Using php to connect to Oracle Database 11g Release 2 Enterprise Edition EE
Greetings everyone!
Please i dont know how to connect to Oracle Database 11g Release 2 Enterprise Edition with php even though i connected with php successfully with Oracle Database 11g Express Edition with the php code below. can someone help please...Note im referring to oracle EE not XE.
define('ORA_CON_UN', 'hr'); // User name
define('ORA_CON_PW', 'Adlibs14$'); // Password
define('ORA_CON_DB', '//localhost/EE'); // Connection identifier
// use constants defined in anyco_cn.inc
$conn = oci_pconnect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);
if (!$conn) {
db_error(null, __FILE__, __LINE__);
Edited by: user11273096 on Jul 15, 2011 12:03 AMFind the hostname and service name of the database and use those values in the ORA_CON_DB constant.
Use 'lsnrctl status' on the database host to find the service name.
If you use a "tns" alias, you may need to create a tnsnames.ora file where PHP can access it.
Set the environment variable TNS_ADMIN (on Linux) to the directory containing the file.
See the section "Oracle Database Name Connection Identifiers" p 102 of the free book
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html -
Cant connect to Oracle database using oracle db client
Hi All,
I recently created a virtual machine running windows server 2008 on my windows 7 host. Oracle database 11g is already installed on host OS(windows 7) and I have installed oracle 11g client on the guest OS(windows server 2008) and trying to connect to oracle database from remote server using oracle client but getting this error:
ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATAI am trying to connect using oracle client as below:
C:\Users\Administrator>SET ORACLE_SID = HR84DEV
C:\Users\Administrator>SQLPLUS /NOLOG
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 10 06:16:34 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> CONNECT SYSADM/[email protected]
ERROR:
ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA
I have created database with name - HR84DEV
HOST ip address is - 192.168.56.1
I googled this error and as most of resources/blogs talked about having correct entry on listner.ora and tnsnames.ora file, I did the changes on both of these files accordingly.
PFB the cotent of both of these files:
tnsnames.ora
# tnsnames.ora Network Configuration File: C:\MyApps\Oracle\product\11.2.0\dbhome_\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
HR84DEV =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = HR84DEV)
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
listner.ora
# listener.ora Network Configuration File: C:\MyApps\Oracle\product\11.2.0\dbhome_\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\MyApps\Oracle\product\11.2.0\dbhome_)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:C:\MyApps\Oracle\product\11.2.0\dbhome_\bin\oraclr11.dll")
(SID_DESC =
(SID_NAME = HR84DEV)
(ORACLE_HOME = C:\MyApps\Oracle\product\11.2.0\dbhome_)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:C:\MyApps\Oracle\product\11.2.0\dbhome_\bin\oraclr11.dll")
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
ADR_BASE_LISTENER = C:\MyApps\Oracle
Please not that I dont have any problem in connect to database locally.Thanks Nicolas,
Actually, there was a problem with my oracle client installation. I uninstalled it and then installed back again but still, even after following your instructions I get some error.
Here what I did:
Created tnsnames.ora file as below:
HR84DEV =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.1)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = HR84DEV)
Placed it under appropriate directory and then checked the connection with database using the command shown below:
C:\Users\Administrator>tnsping HR84DEV
TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 10-FEB-2
012 08:42:03
Copyright (c) 1997, 2010, Oracle. All rights reserved.
Used parameter files:
C:\MyApps\Administrator\product\11.2.0\client_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.56.1)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = HR84DEV)))
OK (20 msec)
Then tried to connect to database as below:
C:\Users\Administrator>SET ORACLE_SID=HR84DEV
C:\Users\Administrator>SQLPLUS /NOLOG
SQL*Plus: Release 11.2.0.1.0 Production on Fri Feb 10 08:25:56 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
SQL> CONNECT SYSADM/SYSADM@HR84DEV
ERROR:
ORA-28547: connection to server failed, probable Oracle Net admin error
But still getting error.
I Googled this error and tried to figure out what the problem is and came across the possible cause which is because I haven't specify that the service should run as a user who is in domain admin group.
well, I am not really sure about this and dont know what user name and password I should enter in OracleserviceHR84DEV-properties-log on-this account.
do I really need to set this? -
Connect to oracle database using c program
I am using AIX environment and i want to connect to oracle database using c program.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10825/pc_03dbc.htm#i5880
-
How to connect to database through TOAD(using tnsnames & sqlnet)
Hi All,
Hope everyone doing fine.. Actually i am new to oracle. Oracle9i and TOAD 9.7.0.51 are installed in my office PC. When I try to connect to the database through TOAD i am getting ORA-12560: TNS:protocol adapter error.
And i've the tnsname details.
Now i want to connect to the database.But i am not aware of the process about what to do. So Can anyone please help me on the above problem.
Please give the steps to follow(one by one)
Thanks,
mkrOracle9i and TOAD 9.7.0.51 are installed in my office PC.sqlplus> connect / as sysdba
connected.
Check your $ORACLE_HOME/network/admin/tnsnames.ora
If it does not exist create as an example.
example
DBX =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = <host or ip>)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME =<sid_name>)
set ORACLE_SID=SID
tnsping DBX
try to connect by toad after that it should work... -
Using php to connect to Oracle Database 11g Release 2 Enterprise Edition
Greetings everyone!
Please i dont know how to connect to Oracle Database 11g Release 2 Enterprise Edition with php even though i connected with php successfully with Oracle Database 11g Express Edition with the php code below. can someone help please...
define('ORA_CON_UN', 'hr'); // User name
define('ORA_CON_PW', 'Adlibs14$'); // Password
define('ORA_CON_DB', '//localhost/XE'); // Connection identifier
// use constants defined in anyco_cn.inc
$conn = oci_pconnect(ORA_CON_UN, ORA_CON_PW, ORA_CON_DB);
if (!$conn) {
db_error(null, __FILE__, __LINE__);
Edited by: user11273096 on Jul 14, 2011 3:41 PMNote that this forum is for XE Beta, not EE.
Can you connect from some other client tool, such as sqlplus?
There's a {forum:id=178} forum that may be more suitable, if basic connectivity outside php works (i.e. issue is only php specific). -
ODI topology connection error - oracle database
Hi,
I'm trying to connect to oracle database installed on a remote server through odi client installed on my windows machine. Oracle db is on RHEL 64 bit, I believe. I know the connection details such as hostname, sid etc but i'm not able to establish a connection using the oracle jdbc driver. I can perfectly connect to the db via sqldeveloper using tnsnames and also basic connection which rules out the possibility that i might be giving incorrect SID name in ODI connection since I'm using the same details for both
Error which i received is:
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
at oracle.odi.jdbc.datasource.LoginTimeoutDatasourceAdapter.doGetConnection(LoginTimeoutDatasourceAdapter.java:133)
at oracle.odi.jdbc.datasource.LoginTimeoutDatasourceAdapter.getConnection(LoginTimeoutDatasourceAdapter.java:62)
at com.sunopsis.sql.SnpsConnection.testConnection(SnpsConnection.java:1125)
at com.sunopsis.graphical.dialog.SnpsDialogTestConnet.getLocalConnect(SnpsDialogTestConnet.java:163)
at com.sunopsis.graphical.dialog.SnpsDialogTestConnet.access$4(SnpsDialogTestConnet.java:159)
at com.sunopsis.graphical.dialog.SnpsDialogTestConnet$4.doInBackground(SnpsDialogTestConnet.java:519)
at com.sunopsis.graphical.dialog.SnpsDialogTestConnet$4.doInBackground(SnpsDialogTestConnet.java:1)
at oracle.odi.ui.framework.AbsUIRunnableTask.run(AbsUIRunnableTask.java:258)
at oracle.ide.dialogs.ProgressBar.run(ProgressBar.java:655)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
at oracle.odi.jdbc.datasource.LoginTimeoutDatasourceAdapter.doGetConnection(LoginTimeoutDatasourceAdapter.java:133)
at oracle.odi.jdbc.datasource.LoginTimeoutDatasourceAdapter.getConnection(LoginTimeoutDatasourceAdapter.java:62)
at oracle.odi.core.datasource.dwgobject.support.OnConnectOnDisconnectDataSourceAdapter.getConnection(OnConnectOnDisconnectDataSourceAdapter.java:74)
at oracle.odi.jdbc.datasource.LoginTimeoutDatasourceAdapter$ConnectionProcessor.run(LoginTimeoutDatasourceAdapter.java:217)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
... 1 more
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:482)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:678)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:238)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:567)
at oracle.odi.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:410)
at oracle.odi.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:386)
at oracle.odi.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:353)
at oracle.odi.jdbc.datasource.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:332)
... 7 more
Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:411)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1222)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:330)
... 15 moretnsping works fine. To solve the problem, I changed my JDBC connection string to another format which uses connect description with service name and that solved the problem. This is what I used.
jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on) (ADDRESS=(PROTOCOL=TCP)(HOST=) (PORT=1521)) (ADDRESS=(PROTOCOL=TCP)(HOST=) (PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=))) -
DBA studio: Error add/connect database "Failed to parse tnsnames.ora file"
I have Oracle (version 8.1.7) installed in my XP machine and when I try to (having chosen "Launch DBA Studio standalone") to open a connection I get:
"Failed to parse tnsnames.ora file
ERROR: 100 -- NLNV-NLNV String Format Error".
Also got this when I tried to manually add a database to a tree.
I can access the databases listed in my tnsnames.ora using SQL Plus with no error.
This is my tnsnames.ora.
# TNSNAMES.ORA Network Configuration File: C:\oracle\ora81\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
INST1_HTTP.xx.yy.GE.COM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = MyMachine3)(PORT = 1521))
(CONNECT_DATA =
(SERVER = SHARED)
(SERVICE_NAME = buch3ora)
(PRESENTATION = http://admin)
EXTPROC_CONNECTION_DATA.xx.yy.GE.COM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
MyOra3.xx.yy.GE.COM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = MyMachine3)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = ora3)
OORCL.xx.yy.GE.COM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 3.4.55.66)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = oorcl))
Does anybody have any idea what is wrong? Thanks a lot. ChangsongJust found out this IS a string error in my Tnsname.ora. What i did is deleting all the entries in my tnsname.ora, and start adding each one back. I found one particular entry is responsible for the error. This is the old text
serv32.xxx.ge.com =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (COMMUNITY = TCP)(PROTOCOL = TCP)(HOST = sevr32.xxy.ge.com)(PORT = 1521))
(CONNECT_DATA = (SID = atmo32))
just looking by itself I can't see anything wrong. I just formatted it a little, making it looked like the other one that is working
serv32.xxx.ge.com =(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = TCP)
(PROTOCOL = TCP)
(HOST = sevr32.xxy.ge.com)
(PORT = 1521)))
(CONNECT_DATA=
(SID = atmo32)))
and now it works fine. I Really can't tell the difference, except that some words were moved to the other line. What puzzled me is that the same old tnsname.ora worked in almost all the other circumstances, like sql plus, and other database enginee. But it is just not good enough for dba studio?
I admit I probably should have used the network utility to add a connection to avoid this type of format error.
Anyhow, I'm glad it is solved. by the way, the symjct.dll mentioned in the previous post should be symcjit.dll. I guess he mispelled the name. I renamed it to symcjit_old.dll and now the java error was gone. So that is another gain from this post. Thanks Joel for all the information. -
Unable to connect to Oracle database running on Windows machine from linux.
Hi,
I'm not able to connect to oracle database running on Windows machine from Linux machine. I'm geting the below mentioned error. I have given below the code I used to connect to database and database propertes.Do I need to use any specific driver?
Please help me.
Thanks,
Sunjyoti
Code :
import oracle.jdbc.pool.OracleDataSource;
import java.sql.Connection;
import java.util.*;
import java.sql.*;
import java.io.*;
class try2{
public static void main(String args[]) {
try {
System.out.println("hi");
// Load the properties file to get the connection information
Properties prop = new Properties();
prop.load(new FileInputStream("/home/sreejith/EDIReader/Connection.properties"));
// Create a OracleDataSource instance
OracleDataSource ods = new OracleDataSource();
System.out.println("prop is "+prop);
configureDataSource(ods, prop);
Connection conn=null;
// Create a connection object
conn = ods.getConnection();
System.out.println("Connection is"+conn);
// Sets the auto-commit property for the connection to be false.
conn.setAutoCommit(false);
} catch (SQLException sqlEx){ // Handle SQL Errors
System.out.println("In exception "+sqlEx);
} catch(Exception excep) { // Handle other errors
System.out.println(" Exception "+ excep.toString());
private static void configureDataSource(OracleDataSource ods, Properties prop) {
// Database Host Name
ods.setServerName(prop.getProperty("HostName"));
// Set the database SID
ods.setDatabaseName(prop.getProperty("SID"));
// Set database port
ods.setPortNumber( new Integer( prop.getProperty("Port") ).intValue());
// Set the driver type
ods.setDriverType ("thin");
// Sets the user name
ods.setUser(prop.getProperty("UserName"));
// Sets the password
ods.setPassword(prop.getProperty("Password"));
Connection properties :
# Your Database Connection details
HostName = 10.20.3.19
SID = EDIREAD
Port = 1521
UserName = dbuser
Password = dbuser
Error I'm getting is
error while trying to connect with odbc datasource
[root@iflexpau2217 EDIReader]# java try2
hi
prop is {HostName=10.20.3.19, Password=dbuser, UserName=dbuser, SID=EDIREAD, Port=1521}
In exception java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
Also I tried to connect with weblogic JDBC driver
Code is here:
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
//import com.entrust.toolkit.util.ByteArray;
public class trial{
public static void main(String args[]) throws IOException{
System.out.println("hi");
Connection p_conn = null;
PreparedStatement xml_insert = null;
try {
// Load the JDBC driver
System.out.println("hi2");
// String driverName = "oracle.jdbc.driver.OracleDriver";
String driverName = "weblogic.jdbc.oracle.OracleDriver";
System.out.println("hi2");
Class.forName(driverName);
// Create a connection to the database
String serverName = "10.20.3.19";
String portNumber = "1521";
String sid = "EDIREAD";
//String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String url = "jdbc:bea:oracle://10.20.3.19:1521";
String username = "dbuser";
String password = "dbuser";
System.out.println("connection is:"+p_conn+"user name is"+username+"password is"+password);
p_conn = DriverManager.getConnection(url, username, password);
System.out.println("connection is:"+p_conn+"user name is"+username+"password is"+password);
xml_insert=p_conn.prepareStatement("insert into PRTB_SUBUNIT (SUBUNT_ID,SUBUNT_SUB_UNIT,SUBUNT_PHYUNT_ID) values (?,?,?)");
//InputStream in=null;
File l_file=new File("/home/sreejith/EDIReader/propertyfiles/inputfile/BUG_10802_ES_CSB19_68.txt");
BufferedReader input =null;
input=new BufferedReader(new FileReader(l_file));
String line = null;
StringBuffer trial=new StringBuffer();
while (( line = input.readLine()) != null){
trial.append(line);
trial.append(System.getProperty("line.separator"));
//InputStream is = new BufferedInputStream(new FileInputStream(l_file));
System.out.println(trial.toString());
//Blob b ;
//byte[] bytes=trial.toString().getBytes();
//System.out.println("Size-->"+bytes.length);
xml_insert.setString(1,new String("SpecailChar"));
//xml_insert.setBinaryStream(2,new ByteArrayInputStream(bytes),15920);
xml_insert.setString(3,"SpecailChar");
xml_insert.executeUpdate();
p_conn.commit();
} catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException:"+e.getMessage());
// Could not find the database driver
} catch (SQLException e) {
System.out.println("SQEXCEPTIN:"+e.getMessage());
// Could not connect to the database
}catch (FileNotFoundException e) {
System.out.println("filenot found:"+e.getMessage());
// Could not connect to the database
Error I'm getting is
error while trying with jdbc:
SQEXCEPTIN:[BEA][Oracle JDBC Driver]Error establishing socket to host and port: 10.20.3.19:1521. Reason: Connection refusedIs the Windows firewall active? Have you enabled the port on the firewall, if it is?
-
Connection of oracle database in database server from application server
Hi,
I have two servers, one is application server and another one is database server…..
I want to connect oracle 10g database in database server to application server. In application server oracle 10g client is installed……In database server, I have set tnsnames.ora, Listener.ora …while checking in lsnrctl…the particular sid is running fine…
In application server, while I give as sqlplus
After giving username and password its showing error as
ORA-12545: Connect failed because target host or object does not exist
While surfing in net it shows check tnsnames.ora and listener.ora….. I have set the environmental variables here in application server…..
It’s connecting when I give
Sqlplus
Sql>username/password @ hostname: 1521/sid_name
Is it possible to connect with the username and password
I have set the host names in /etc/hosts….
If we are giving the hostname, port number and Sid name this connects without using tnsnames.ora…..
While pinging between two servers the connectivity is there between two servers…..
Could u pls help me out?
Thanks in advancehi,
as u said i have done that ..s.till the same problem persists...
lsnrctl>services
$ lsnrctl
LSNRCTL for IBM/AIX RISC System/6000: Version 10.2.0.1.0 - Production on 08-FEB-2007 03:56:23
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL> services
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
Services Summary...
Service "RBTT" has 1 instance(s).
Instance "RBTT", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER
Service "RBTTXDB" has 1 instance(s).
Instance "RBTT", status READY, has 1 handler(s) for this service...
Handler(s):
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER <machine: emea, pid: 197076>
(ADDRESS=(PROTOCOL=tcp)(HOST=emea)(PORT=37484))
Service "RBTT_XPT" has 1 instance(s).
Instance "RBTT", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:0 refused:0 state:ready
LOCAL SERVER -
How to connect to Oracle database from webdynprojava application
Hi
How to connect to Oracle database from webdynprojava application. where can we provide the code to connect to database.?
Thank You.Hi,
You need to create Java Bean model. The bean is a typical java bean with default constructor, getter and setter. You can have additional methods for query etc. The attributes in the class will be your model node and attributes.
However you need to configure the connection and create JNDI using visual administrator before writing the code.
You can also consider writing Session EJB with oracle and using them in WD.
http://help.sap.com/saphelp_nwce10/helpdata/en/45/dcaa4f05535591e10000000a1553f7/frameset.htm
Srini -
Connect to Oracle database from SQL Sever
Can you help on an issue of connection from SQL Server to Oracle database:
In SQL Server, I create a "linked server" to connect to Oracle database on a different machine. But it will take a unreasonable time (about 30 seconds) to call a Oracle query from SQL Server.No there are no entries required in the TNSNAMES.ORA
When you are using ODBC for connection, Oracle does not look fo rany enteries in TNSNAMES.ORA file.
Now I am able to connect to both SQL Plus and Forms 6i. But while connecting to SQL Plus its giving an error
Error accessing PRODUCT_USER_PROFILE
Warning: Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM
Server not available or version too low for this feature
Connected to:
Oracle Open Client Adapter for ODBC 6.0.5.35.0
Microsoft SQL Server 08.00.0534
Also while disconnecting the Windows Program Error comes, and the application closes abruptly.
Maybe you are looking for
-
Portal Events---WDA view is empty on initialization
Hello everyone, I created a WDA application which will be integrated with Employee Search Iview (provided by SAP). Everything is working fine...only issue is that when we display the page first time...my WDA view is empty...untill we click on an emp
-
HT4356 I don't have wireless printer. How can I print out the document?
I don't have a wireless printer. How can I print out the document from regular printer?
-
Not able to open office documents from SharePoint site using Forms auth on a Mac with Office 2011
I posted the same question on the Mac Office forum (http://answers.microsoft.com/en-us/mac/forum/macoffice2011-macstart/not-able-to-open-office-documents-from-sharepoint/7fba517b-ebd1-4e90-a54a-c70c5f035146?tm=1418836613595) but figured it's probably
-
The Add-on installation is currently in phase DDIC_ACTIVATION
Dear All, I am applying the addon "ST-A/PI" on SAP ERP 6.0. The status "The Add-on installation is currently in phase DDIC_ACTIVATION" has been there for a few hours now whereas the sap note says it should end in 12 mins approx. Could you please help
-
How does one create age restricted articles inside DPS?
Hello all, I need to know how to create an article that is age restricted. Are there any setting within InDesign etc. that can do this, or shall I use HTML in a web overlay? Thoughts or example etc., greatly received and much appreciated. Cheers, Bil