I am trying to connect to oracle database using JDBC.
following is the code::
public class OraclePwdTest {
static{
try {
Clas
When special characters are there in username, password or connection string like @
, /
etc., we have to include it within double quoted, for example, if the password is p@ssword
we connect in sqlplus as username/"p@ssword"@database
You can try the same in java by enclosing your password in double quotes using escape characters, try changing
String pwd = "s@novi123";
to
String pwd = "\"s@novi123\"";
I am not a java expert, just guessed the scape character should be \
;-)
A simple code would looks like this... As you are using thin driver you don't need to complicate with all those values from tnsnames.ora.
Class.forName("oracle.jdbc.OracleDriver");
Properties properties = new Properties();
properties.setProperty("user", username);
properties.setProperty("password", password);
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@<DB_HOST>:<PORT>:<SID>, properties);
ie. jdbc:oracle:thin:@192.168.20.145:1521:oradg