shell_exec("ssh -f -L 127.0.0.1:3307:127.0.0.1:3306 user@remote.rjmetrics.com sleep 60 >>logfile")$db = mysqli_connect("127.0.0.1", "sqluser", "sqlpassword", "rjmadmin", 3307)
DB接口:package org.xxx.dbc
import java.sql.Connection
public interface IDatabaseConnection {
public Connection getConnection() throws Exception
public void close() throws Exception
}
------------------------------------------------------------------
实现:
package org.xxx.dbc.impl
import java.sql.Connection
import java.sql.DriverManager
import org.xxx.dbc.IDatabaseConnection
public class OracleDatabaseConnection implements IDatabaseConnection {
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver"
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:db1" public static final String DBUSER = "name"
public static final String DBPASS = "pass"
private Connection conn = null
@Override
public void close() throws Exception {
// TODO Auto-generated method stub
try {
if (this.conn != null) {
this.conn.close()
}
} catch (Exception e) {
throw e
}
}
@Override
public Connection getConnection() throws Exception {
// TODO Auto-generated method stub
try {
Class.forName(DBDRIVER)
this.conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS)
} catch (Exception e) {
throw e
}
return this.conn
}
}
----------------------------------------------------------------------------------
工厂
package org.xxx.dbc.factory
import org.xxx.dbc.IDatabaseConnection
import org.xxx.dbc.impl.OracleDatabaseConnection
public class DBCFactory {
public static IDatabaseConnection getOracleDatabaseConnection()throws Exception {
return new OracleDatabaseConnection()
}
}
看错了,以为是oracle .不影响使用
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)