开发环境是:jdk1.4.3、resin3.0
dbconn.java:
package com.pixel;import java.sql.*;
import java.util.*;
import java.io.File;
import java.io.*;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;public class DBConn implements Runnable {
private String jdbcDriver = "";
private String dbUrl = "";
private String dbUsername = "";
private String dbPassword = "";
private String testTable = "dual";
private int initialConnections = 10;
private int incrementalConnections = 5;
private int maxConnections = 30;
private Vector connections = null;
private long wait=30000;
public DBConn() throws Exception {
Properties prop = new Properties();
try {
//读入配置文件
prop.load(getClass().getResourceAsStream("/../service_properties.conf"));
this.jdbcDriver = prop.getProperty("Driver");
this.dbUrl = prop.getProperty("Url");
this.dbUsername = prop.getProperty("Username");
this.dbPassword = prop.getProperty("Password"); log("Web Server connect to : " + dbUrl);
createPool(); new Thread(this).start();
} catch (FileNotFoundException ex) {
throw ex;
}
} public void run() {
try {
while (true) {
Thread.sleep(wait);
System.out.println(new java.util.Date() + " 开始清理连接池");
timerEvent();
}
}
catch (InterruptedException e) {
}
}
public int getInitialConnections() {
return initialConnections;
} public void setInitialConnections(int initialConnections) {
this.initialConnections = initialConnections;
}
public int getIncrementalConnections() {
return incrementalConnections;
} public void setIncrementalConnections(
int incrementalConnections) {
this.incrementalConnections = incrementalConnections;
} public int getMaxConnections() {
return maxConnections;
} public void setMaxConnections(int maxConnections) {
this.maxConnections = maxConnections;
} public String getTestTable() {
return testTable;
} public void setTestTable(String testTable) {
this.testTable = testTable;
} public synchronized void createPool() throws Exception {
//make sure that createPool hasn't already been called
if (connections != null) {
return; //the pool has already been created, return
} //instantiate JDBC driver object from init param jdbcDriver
Driver driver = (Driver)
(Class.forName(jdbcDriver).newInstance()); DriverManager.registerDriver(driver); //register JDBC driver connections = new Vector(); //creates the proper number of initial connections
createConnections(initialConnections);
}
请问各位怎么解决?多谢各位了,续下
dbconn.java:
package com.pixel;import java.sql.*;
import java.util.*;
import java.io.File;
import java.io.*;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;public class DBConn implements Runnable {
private String jdbcDriver = "";
private String dbUrl = "";
private String dbUsername = "";
private String dbPassword = "";
private String testTable = "dual";
private int initialConnections = 10;
private int incrementalConnections = 5;
private int maxConnections = 30;
private Vector connections = null;
private long wait=30000;
public DBConn() throws Exception {
Properties prop = new Properties();
try {
//读入配置文件
prop.load(getClass().getResourceAsStream("/../service_properties.conf"));
this.jdbcDriver = prop.getProperty("Driver");
this.dbUrl = prop.getProperty("Url");
this.dbUsername = prop.getProperty("Username");
this.dbPassword = prop.getProperty("Password"); log("Web Server connect to : " + dbUrl);
createPool(); new Thread(this).start();
} catch (FileNotFoundException ex) {
throw ex;
}
} public void run() {
try {
while (true) {
Thread.sleep(wait);
System.out.println(new java.util.Date() + " 开始清理连接池");
timerEvent();
}
}
catch (InterruptedException e) {
}
}
public int getInitialConnections() {
return initialConnections;
} public void setInitialConnections(int initialConnections) {
this.initialConnections = initialConnections;
}
public int getIncrementalConnections() {
return incrementalConnections;
} public void setIncrementalConnections(
int incrementalConnections) {
this.incrementalConnections = incrementalConnections;
} public int getMaxConnections() {
return maxConnections;
} public void setMaxConnections(int maxConnections) {
this.maxConnections = maxConnections;
} public String getTestTable() {
return testTable;
} public void setTestTable(String testTable) {
this.testTable = testTable;
} public synchronized void createPool() throws Exception {
//make sure that createPool hasn't already been called
if (connections != null) {
return; //the pool has already been created, return
} //instantiate JDBC driver object from init param jdbcDriver
Driver driver = (Driver)
(Class.forName(jdbcDriver).newInstance()); DriverManager.registerDriver(driver); //register JDBC driver connections = new Vector(); //creates the proper number of initial connections
createConnections(initialConnections);
}
请问各位怎么解决?多谢各位了,续下
prop.load(getClass().getResourceAsStream("/../service_properties.conf"));
没有得到配置文件报的错
代码是:
Driver = oracle.jdbc.driver.OracleDriver
Url = jdbc:oracle:thin:@127.0.0.1:1521:pixel
Username = gaokao
Password = gaokao
pixel\dbconn/java
为prop.load(getClass().getResourceAsStream("service_properties.conf"));