Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

not able to hit the database through java program

Posted on 2009-07-03
12
Medium Priority
?
937 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 200 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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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 Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

916 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