Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

not able to hit the database through java program

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
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Please show how you connect via sqlplus.

sqlplus deliverytest7/dbpasword

SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of gudii9

ASKER

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

Avatar of gudii9

ASKER

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
Avatar of gudii9

ASKER

through command prompt also i was able to connect as in screenshot
Avatar of gudii9

ASKER

screenshot is like this
sql-plus-2.JPG
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

thank you very much for your help