Connection connection = null;
Statement stmt = null;
String strDriver = "oracle.jdbc.driver.OracleDriver";
String strURL = "jdbc:oracle:thin:@192.168.210.88:1521:unieap";
String strUser = "orgeap";
String strPwd = "orgeap";
String strSQL = "select * from cities"; try {
Class.forName(strDriver);
connection = DriverManager.getConnection(strURL, strUser, strPwd);
stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(strSQL);
.....
} catch (Exception e) {
....
}
Statement stmt = null;
String strDriver = "oracle.jdbc.driver.OracleDriver";
String strURL = "jdbc:oracle:thin:@192.168.210.88:1521:unieap";
String strUser = "orgeap";
String strPwd = "orgeap";
String strSQL = "select * from cities"; try {
Class.forName(strDriver);
connection = DriverManager.getConnection(strURL, strUser, strPwd);
stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(strSQL);
.....
} catch (Exception e) {
....
}
unieap : 数据库的sid即全局名
strUser : 用户名
strPwd : 密码
最好用连接池配!
try {
Context env = (Context) new InitialContext().lookup("java:comp/env");
pool = (DataSource) env.lookup("jdbc/test");
} catch (NamingException e) {
}在resion里的配置文件应该这样写了:
<resource-ref>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<init-param driver-name="oracle.jdbc.driver.OracleDriver"/>
<init-param url="jdbc:oracle:thin:@192.168.210.88:1521:unieap"/>
<init-param user=""/>
<init-param password=""/>
<init-param max-connections="20"/>
<init-param max-idle-time="30"/>
</resource-ref>抄袭一下。哈哈。
可以不用jdbc桥连接吗?