gudii9
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.Or acleDriver ");
// or you can use:
// DriverManager.registerDriv er(new oracle.jdbc.driver.OracleD river());
Connection conn = DriverManager.getConnectio n("jdbc:or acle:thin: @localhost :1521:orcl ","deliver ytest7","d bpasword") ;
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from stud");
while(rset.next())
{
System.out.println(rset.ge tInt(1));
System.out.println(rset.ge tString(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
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
// or you can use:
// DriverManager.registerDriv
Connection conn = DriverManager.getConnectio
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select * from stud");
while(rset.next())
{
System.out.println(rset.ge
System.out.println(rset.ge
}
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
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
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?
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.
dbpasword OR dbpassword (i.e. double ss).
Show the : sqlplus user/pass@orcl result as pointed out by mrjoltcola.
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.getConnectio n("jdbc:or acle:thin: @localhost :1521:orcl ","deliver ytest7","d bpasword") ;
Please advise
sql-plus.JPG
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.getConnectio
Please advise
sql-plus.JPG
ASKER
through command prompt also i was able to connect as in screenshot
ASKER
screenshot is like this
sql-plus-2.JPG
sql-plus-2.JPG
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you very much for your help
sqlplus deliverytest7/dbpasword