Solved

not able to hit the database through java program

Posted on 2009-07-03
12
903 Views
Last Modified: 2012-05-07
Hi,

I am running follwoing java program to select, insert values into oracle 10g dfatabase table through RAD workspace.




import java.sql.*;



class dbtest {



 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:@localhost:1521:orcl","deliverytest7","dbpasword");


   Statement stmt = conn.createStatement();

   ResultSet rset = stmt.executeQuery("select * from stud");

   while(rset.next())

    {

     System.out.println(rset.getInt(1));

     System.out.println(rset.getString(2));

     }

   rset.close();

   stmt.close();

   conn.close();

 }

}


It gives error message like invalid user name and password. I am able to connect to same schema through sql plus without any issues. Please advise. Any links, ideas, resources highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24774292
Please show how you connect via sqlplus.

sqlplus deliverytest7/dbpasword

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 50 total points
ID: 24774302
>>I am able to connect to same schema through sql plus without any issues.

There's got to be something different. Are you sure it's not a different copy of the db?
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24774308
I agree with Charles. Invalid username/password error means you hit the instance.

That is why I want to see the explicit command used to connect via sqlplus.

Are there different dbs on the same box?

Also show:  lsnrctl services
0
 
LVL 7

Author Comment

by:gudii9
ID: 24774310
It is same copy of database schema i am hitting. I am able to connect using sqldeveloper also as in screenshot similar to sqlplus.
sql-developer.JPG
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24774324
That is fine, but please answer the specific questions above.

Oracle JDBC service name syntax requires a / in the JDBC URL nowadays. Your JDBC URL is using SID syntax (which is ok, but I am just pointing out the difference), yet your SQL Developer connection is using service syntax. Please try the SID option, or use sqlplus.

sqlplus user/pass@orcl

Again, how many databases are on your system?
0
 
LVL 12

Expert Comment

by:basav_com
ID: 24774354
May be sillypoint.. but still wants to point out. Password is:
dbpasword     OR     dbpassword           (i.e. double ss).

Show the : sqlplus user/pass@orcl             result as pointed out by mrjoltcola.

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 7

Author Comment

by:gudii9
ID: 24774366
I only have one database running in my laptop with xp OS. Sqlplus i am not connecting through command prompt but from


start-->all programs--->oracle oracle 10g--->sqlplus etc as in screnshot.

How shall i change following statement to include service name instead of SID

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","deliverytest7","dbpasword");


Please advise
sql-plus.JPG
0
 
LVL 7

Author Comment

by:gudii9
ID: 24774381
through command prompt also i was able to connect as in screenshot
0
 
LVL 7

Author Comment

by:gudii9
ID: 24774392
screenshot is like this
sql-plus-2.JPG
0
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 50 total points
ID: 24774432
I don't understand why it is so difficult for you to follow my explicit directions above?

The reason I am asking you to connect with the _explicit_ syntax is to force the use of the TNS alias, if it exists. You've also not provided the output to the info asked for in:  http:#24774308

So, one last time, please try:

1) sqlplus deliverytest8/passwordxxx@orcl

2) Also show output of: lsnrctl services

0
 
LVL 12

Accepted Solution

by:
basav_com earned 400 total points
ID: 24774433
From the posted screenshot, from the password field I can see 10 masked stars. So, I guess the correct password is 'dbpassword'(10 digits) and not 'dbpasword' (9 digits).

Can you post the EXACT output of the following commands.

1. sqlplus deliverytest7/dbpasword

2. sqlplus deliverytest7/dbpassword
0
 
LVL 7

Author Closing Comment

by:gudii9
ID: 31599668
thank you very much for your help
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Extract the first word (before the , ) 2 40
eclipse argument 14 53
SQL Query 34 82
even odd program using while loop 3 29
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video teaches viewers about errors in exception handling.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now