java - Accessing oracle database via SID through JDBC without host:port -
when i'm looking information on how connect oracle database via jdbc, find same solutions show how connect known host:port. have pass connect string
jdbc:oracle:thin:[user/password]@[host][:port]:sid
to jdbc , works.
protected connection connect() { connection conn; try { class.forname(oracle.jdbc.oracledriver.class.getcanonicalname()); } catch (classnotfoundexception e) { return null; } try { conn = drivermanager.getconnection("jdbc:oracle:thin:@1.1.1.1:1536:sid", "user", "passwd"); } catch (sqlexception e) { return null; } return conn; }
the problem approach though is, have find out on host:port database is. when use database tools pl/sql developer
or others, don't need this. user prompted database name , the tool can somehow connect nevertheless. know how done. achieve requiring tnsping
in path, , in helper class (not shown in above example code), provides connect url, call tnsping
, parse output. not method, , wondering if there proper way connect.
you not able using normal jdbc (thin driver). may try using oci, apparently understand tns entries.
Comments
Post a Comment