Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

I try to connect oracle cloud and eclipse but something wrong

User_RYYKBNov 25 2021

I used oraclecloud wallet
public class DbTest {

public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.OracleDriver");
System.out.println("Driver 등록");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

DbTest db = new DbTest();  
int result = db.searchTable();  
System.out.println("조회결과 : "+result);  

}

public Connection getConnection() {
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:oracle:thin:@DB202111242136_high?TNS_ADMIN=C: \\dev\\wallet\\wallet\\Wallet_DB202111242136", "geverytime", "Semiproject1234");
//
conn.setAutoCommit(false);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}

public int searchTable() {
PreparedStatement pstmt = null;
Connection conn = getConnection();
ResultSet rset = null;
int result = 0;

try {  
  pstmt = conn.prepareStatement("select \* from test");  
  rset = pstmt.executeQuery();  

  while(rset.next()) {  
    result = rset.getInt(1);  
  }  

} catch (SQLException e) {  
  e.printStackTrace();  
} finally {  
  try {  
    conn.close();  
  } catch (SQLException e) {  
    e.printStackTrace();  
  }  
}  

return result;  

}

}
//this is testcode for connection with oracle cloud
I using window and ojdbc.jar is added on WEB-INF-lib
and showing error like this what is the problem??
IO error : Invalid connection string format, a valid format is: "host:port:sid"

Comments
Post Details
Added on Nov 25 2021
0 comments
187 views