当前位置: 技术问答>java相关
请问。我的Oracle的数据库连接应该怎么写??一直不对。谢谢
来源: 互联网 发布时间:2017-04-02
本文导语: Oracle9i,连接到网络中的一台Oracle数据库,肯定是通的。 1: String driver="oracle.jdbc.driver.OracleDriver"; //9i的是这样么? try{ Class.forName(driver); System.out.println("Load driver success"); } catch(Exception e)...
Oracle9i,连接到网络中的一台Oracle数据库,肯定是通的。
1: String driver="oracle.jdbc.driver.OracleDriver"; //9i的是这样么?
try{
Class.forName(driver);
System.out.println("Load driver success");
}
catch(Exception e){
System.out.println("Can't Load driver");
}
程序直接就运行到了 "Can't Load driver,没有加载到driver,请问我的字符串应该怎么写??
2:我又改为用ODBC去连接,数据源Myora 测试可以连接到数据库
String url="jdbc:odbc:Myora";
try{
Class.forName(driver);
System.out.println("Load driver success");
}
catch(Exception e){
System.out.println("Can't Load driver");
}
try{
Connection conn=DriverManager.getConnection(url);
if(!conn.isClosed())
System.out.println("Connection DB Success");
conn.close();
}
catch(Exception e){
System.out.println("Can't connect DB");
}
可是这样程序又运行到了。Cant't connect DB; 那我的url又应该怎么写呢?我想是不是要保存用户和密码的问题呢?在建立数据源时,只让我写用户名,没有写密码啊,测试时才临时输入密码的,那么请问是不是要在url这里写用户和密码呢???
谢谢
1: String driver="oracle.jdbc.driver.OracleDriver"; //9i的是这样么?
try{
Class.forName(driver);
System.out.println("Load driver success");
}
catch(Exception e){
System.out.println("Can't Load driver");
}
程序直接就运行到了 "Can't Load driver,没有加载到driver,请问我的字符串应该怎么写??
2:我又改为用ODBC去连接,数据源Myora 测试可以连接到数据库
String url="jdbc:odbc:Myora";
try{
Class.forName(driver);
System.out.println("Load driver success");
}
catch(Exception e){
System.out.println("Can't Load driver");
}
try{
Connection conn=DriverManager.getConnection(url);
if(!conn.isClosed())
System.out.println("Connection DB Success");
conn.close();
}
catch(Exception e){
System.out.println("Can't connect DB");
}
可是这样程序又运行到了。Cant't connect DB; 那我的url又应该怎么写呢?我想是不是要保存用户和密码的问题呢?在建立数据源时,只让我写用户名,没有写密码啊,测试时才临时输入密码的,那么请问是不是要在url这里写用户和密码呢???
谢谢
|
8i:
package jp.co.nec.JTC;
import java.sql.*;
import java.util.*;
import java.io.*;
public class JTCDBConnectionF implements Serializable{
protected Connection con = null;
public JTCDBConnectionF() { }
public void dbOpen() throws java.lang.Exception{
if (con == null || con.isClosed()) {
String url = "jdbc:oracle:oci8:@apsv";
String user = "scott";
String pass = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection(url,user,pass);
con.setTransactionIsolation( con.TRANSACTION_READ_COMMITTED );
con.setAutoCommit(false);
System.out.println("DB OPEN");
} else {
System.out.println("OPENED DB");
}
}
public JTCerrorF dbClose() {
try {
if (con != null && !con.isClosed()) {
con.rollback();
con.close();
System.out.println("DB CLOSE");
} else {
System.out.println("CLOSED DB");
}
}
catch (SQLException se) {
// return new JTCerrorF(se.getErrorCode(),se);
return new JTCerrorF("PD05",se); //DB CLOSE
}
finally {
con = null;
}
return (JTCerrorF)null;
}
}
package jp.co.nec.JTC;
import java.sql.*;
import java.util.*;
import java.io.*;
public class JTCDBConnectionF implements Serializable{
protected Connection con = null;
public JTCDBConnectionF() { }
public void dbOpen() throws java.lang.Exception{
if (con == null || con.isClosed()) {
String url = "jdbc:oracle:oci8:@apsv";
String user = "scott";
String pass = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection(url,user,pass);
con.setTransactionIsolation( con.TRANSACTION_READ_COMMITTED );
con.setAutoCommit(false);
System.out.println("DB OPEN");
} else {
System.out.println("OPENED DB");
}
}
public JTCerrorF dbClose() {
try {
if (con != null && !con.isClosed()) {
con.rollback();
con.close();
System.out.println("DB CLOSE");
} else {
System.out.println("CLOSED DB");
}
}
catch (SQLException se) {
// return new JTCerrorF(se.getErrorCode(),se);
return new JTCerrorF("PD05",se); //DB CLOSE
}
finally {
con = null;
}
return (JTCerrorF)null;
}
}
|
DriverManager registerDriver(new oracle.jdbc.driver.OdbcDriver());--------9i;
你还的确定你的oracle的监听器是不是已经在服务中运行着。
你还的确定你的oracle的监听器是不是已经在服务中运行着。
|
在classpath中申明classes12.jar和nls_charset12.jar,重启机器
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@211.211.211.211:1521:melinets";
String user="system";
String password="manager";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@211.211.211.211:1521:melinets";
String user="system";
String password="manager";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
|
参考一下
#ConnMgr properties
pool.aliascount=1
pool.alias.1=rmms
pool.rmms.driver=oracle
pool.rmms.connstring=jdbc:oracle:thin:@192.168.100.20:1521:DELPHI
pool.rmms.username=RMMS_DEV
pool.rmms.password=EXCEL
pool.rmms.poolsize=1
pool.rmms.timeout=5
pool.rmms.preload=true
pool.rmms.delaytime=1800000
pool.rmms.maxconn=1
pool.rmms.stepincrease=1
pool.rmms.encoding=ISO8859-1
pool.rmms.dbtype=oracle
pool.rmms.db.datetime.left=TO_Date( '
pool.rmms.db.datetime.right=', 'YYYY-MM-DD HH24:MI:SS')
pool.rmms.java.datetime=yyyy-MM-dd hh:mm:ss
pool.rmms.java.date=yyyy-MM-dd
pool.rmms.client.datetime=YYYY-MM-DD HH:MM:SS
pool.rmms.type=exclusive
pool.rmms.preloadstat=false
pool.rmms.statgrpname=
pool.rmms.conn.expire=1800000
pool.rmms.autocommit=false
pool.rmms.conn.precheck=false
#Driver
driver.aliascount=1
driver.alias.1=oracle
driver.classname.oracle=oracle.jdbc.driver.OracleDriver
driver.oracle.preload=true
#ConnMgr properties
pool.aliascount=1
pool.alias.1=rmms
pool.rmms.driver=oracle
pool.rmms.connstring=jdbc:oracle:thin:@192.168.100.20:1521:DELPHI
pool.rmms.username=RMMS_DEV
pool.rmms.password=EXCEL
pool.rmms.poolsize=1
pool.rmms.timeout=5
pool.rmms.preload=true
pool.rmms.delaytime=1800000
pool.rmms.maxconn=1
pool.rmms.stepincrease=1
pool.rmms.encoding=ISO8859-1
pool.rmms.dbtype=oracle
pool.rmms.db.datetime.left=TO_Date( '
pool.rmms.db.datetime.right=', 'YYYY-MM-DD HH24:MI:SS')
pool.rmms.java.datetime=yyyy-MM-dd hh:mm:ss
pool.rmms.java.date=yyyy-MM-dd
pool.rmms.client.datetime=YYYY-MM-DD HH:MM:SS
pool.rmms.type=exclusive
pool.rmms.preloadstat=false
pool.rmms.statgrpname=
pool.rmms.conn.expire=1800000
pool.rmms.autocommit=false
pool.rmms.conn.precheck=false
#Driver
driver.aliascount=1
driver.alias.1=oracle
driver.classname.oracle=oracle.jdbc.driver.OracleDriver
driver.oracle.preload=true
|
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
connect = DriverManager.getConnection(
"jdbc:oracle:thin:@133.166.200.235:1521:orajp","asset","asset");
connect = DriverManager.getConnection(
"jdbc:oracle:thin:@133.166.200.235:1521:orajp","asset","asset");