Solved

not able to hit the database through java program

Posted on 2009-07-03
12
918 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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
 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

730 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