Solved

not able to hit the database through java program

Posted on 2009-07-03
12
901 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video teaches viewers about errors in exception handling.

708 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

18 Experts available now in Live!

Get 1:1 Help Now