aspose file tools*
The moose likes JDBC and the fly likes Problem in connecting Oracle thru Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem in connecting Oracle thru Java" Watch "Problem in connecting Oracle thru Java" New topic
Author

Problem in connecting Oracle thru Java

Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
I have installed Oracle 9i and I want to connect to it using thin driver. I have used the following code,but I am getting the below error
I don't know the default database name. How to find the default database name. The tables like emp,bonus,dept are in the default database while installing oracle 9i. How to find the db name. How can I create a new databse and give privilges? I have TOAD client and I don't know how to configure it with Oracle? Can i get any links on it?
Whether in tnsnames.ora can I able to find out the db?




Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

Who setup your database? You should have a good idea what the name of it is.


My Blog: Down Home Country Coding with Scott Selikoff
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
I have only installed the setup and I have given the SID as ORACLE. And also in the orddata folder, I have found ORACLE.

So db should be correct, username and password should also be correct. Becaus I am opening the sql*plus using the username scott annd password as tiger. then why iam getting this error. How can give more/admin/sysdba privilgies to myself in oracle9i.
sai t
Greenhorn

Joined: Sep 12, 2007
Posts: 1
I think we can't use ORACLE as a database name.To create a new database use "database configuration assistant" which is provided by Oracle where you can create a new database,configure database options in an existing database and many other.
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
Open a SQLPlus session and execute:

select value from v$parameter where name = 'db_name';

Replace "ORACLE" with the value returned.
[ November 27, 2007: Message edited by: Paul Campbell ]
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115

Open a SQLPlus session and execute:

select value from v$parameter where name = 'db_name';

Replace "ORACLE" with the value returned.


Whether the retured value should be replced in TNSNAMES.ORA file:

1. Whether we should not name the db as oracle?
2. I have the following configuration in my TNSNAMES.ORA file:


So, Ihave to replace the ORACLE with the value returned by your query..am I right? I will do it and let you know

I have also tried to connect using ODBC bridge and it has asked for DSN name, and in TNS Service Name , I can able to see the ORACLE and I have selected it and given the username and password and when i tried "Test Connection", I got the below error:
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
if the issue is not having the correct db name for your connection string.

jdbcracle:thin:@mike-dm210ghop:1521:ORACLE

the query returns the name associated with the database you are logged into... which you would use for the database name (if oracle defaulted the name to something different than ORACLE).

If you return "ORACLE" in the query, then your connect string is wrong. If you still can't connect... while the connect string is wrong... you are having another issue affecting your connection.

At the moment, don't touch your tnsnames.ora file since you are not getting a TNS naming error. I'm a little surprised by the connection refused error message... in my limited JDBC experience the error is usually something more along the lines of a reference to the network connector failing (or something like that).
[ November 28, 2007: Message edited by: Paul Campbell ]
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
I am not to resolve the problem. I have created a new db called DTSDB. And I have used the following program for getting connection


Error I am getting:



I have used the following command to find the db name:


of the above only the following below commands only executed properly and given the following results:
SQL> select * from global_name;
SQL> select global_name from global_name;







Plese help to resolve o some other alternative way to proceed and I am hanging around with this problem with more than a week and I could not start my development work..any help..?

My tnsnames.ora File
====================



My listener.ora File:
======================



Do you required any other details? My machine is Windows 2000 OS and I am using Oracle 9i and Java 1.5
[ November 28, 2007: Message edited by: Mike Thomson ]
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
Are your database driver versions in sync with your database version?

You can download them here:

http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
While Installing Oracle 9i itself all the required jars will also be downloaded in the following folder jdbc\lib. I have taken the driver jar from that folder only. Surely, it can't have driver mismacth since the driver jar files are provided by the Oracle 9i installation
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
Just checking since a quick query of people with the same error message suggest their problem was caused by a driver mismatch.
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
Which jar files to use? I have tried with classes12.jar and also ojdbc14_g.jar. I have also have the same setup in my officw machine and I have used classes12.jar and it worked properly

There is any good chnace of firewall problem for this? I am using MCAFEE Antivirus with firewall? But I have tried by disabling the firewall also and I am couldn't get the connection.

Whether reinstalling the oracle will solve the problem?
[ November 30, 2007: Message edited by: Mike Thomson ]
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
okay... taking a step back to the message of "connection refused" and coming up with a list of things to check:

- Check host name in connect string.
- Try numeric IP address of server host in connect string, in case name server is hosed.
- Check port number in connect string.
- Are there any firewalls between client and server.
- Check that the db server is running.
- Check that the db server is listening to the port. On the server, try: "telnet localhost the-port-number". Or "netstat -an", there should be a listening entry for the port.
- Try "telnet serverhost the-port-number" from the client, to see if firewalls are blocking it.
- If "telnet" fails: does it fail immediately or after an obvious timeout? How long is the timeout?
- Does the server respond to "ping theserverhostname"?
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115
I have also googled in net and after a long hours of brpowsing everyone has a problem with a firewall and I am using Mcafee Antivirus and Firewall and I have uninstalled it. And I tried and WOW!! i am not getting this error and I am able to get the connection from oracle using jdbc and thin driver.

But now I am facing a strange problem. If I am opening a tomcat server in 8080 port, it's telling JVM bind error and 8080 has been already used. So I have checked oracle http server abd stopped it in the services. But still i got the same message. Then I have stopped OracleServiceDTS(it's my newly created db service) and now I can able to start the tomcat server and everything is proper. But I want the db to be up for running the application properly.
Sometimes If I type http:\\localhost:8080\asd in the browser, a new pop window is opening and it's asking for username and password. The pop up screen tells Relam:XDB. I have scott as username and tiger as password. It entered into oracle file system.
I am suspecting in oracle also something is listening to 8080 port. How to resolve this. Even though I have resolved the previous problem. now I stuck with this problem as either oracle or tomcat only staring at a time...
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
Oracle uses 8080 and 2100 by default for XMLDB.


-- change HTTP port from 8080 to 8083
call dbms_xdb.cfg_update(updateXML(dbms_xdb.cfg_get(), '/xdbconfig/sysconfig/protocolconfig/httpconfig/http-port/text()', 8083));

-- change FTP port from 2100 to 2111
call dbms_xdb.cfg_update(updateXML( dbms_xdb.cfg_get(), '/xdbconfig/sysconfig/protocolconfig/ftpconfig/ftp-port/text()' , 2111));

-- refresh settings
exec dbms_xdb.cfg_refresh;
[ November 30, 2007: Message edited by: Paul Campbell ]
Mike Thomson
Ranch Hand

Joined: Nov 07, 2007
Posts: 115

-- change HTTP port from 8080 to 8083
call dbms_xdb.cfg_update(updateXML(dbms_xdb.cfg_get(), '/xdbconfig/sysconfig/protocolconfig/httpconfig/http-port/text()', 8083));

-- change FTP port from 2100 to 2111
call dbms_xdb.cfg_update(updateXML( dbms_xdb.cfg_get(), '/xdbconfig/sysconfig/protocolconfig/ftpconfig/ftp-port/text()' , 2111));

-- refresh settings
exec dbms_xdb.cfg_refresh;

Do I need to run this query from SQL*plus?
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
Originally posted by Mike Thomson:

Do I need to run this query from SQL*plus?


That is how I would do it... but anything that allows you to execute PL/SQL likely should allow you to execute the foldering API (the dbms_xdb package)
 
 
subject: Problem in connecting Oracle thru Java