resin.conf文件中配置:其中databaseName,username,password,ip地址需要替换<resource-ref>
<res-ref-name>jdbc/databaseName</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<init-param driver-name="oracle.jdbc.driver.OracleDriver"/>
<init-param url="jdbc:oracle:thin:@127.0.0.1:1521:databaseName"/>
<init-param user="username"/>
<init-param password="password"/>
<init-param max-connections="100"/>
<init-param max-idle-time="30"/>
</resource-ref>
写一个db.java文件import java.sql.*;
import com.caucho.sql.*;public class db { Connection c = null;
DBPool db = null;
public db() {
db = new DBPool();
} public Connection getConnection() throws SQLException {
if (c == null) {
return c = db.getPool("databaseName").getConnection();
}
else {
return c;
}
} public void clsConnection() throws SQLException { if(c != null) c.close(); //close Connection ;
if(db != null) {
/*if not setName(),the class will throw NullPointerException ,
*this is a bug in com.caucho.sql.* package maybe;
*System.out.println(db.toString());
*/
db.setName("poolName");
db.close(); //close DBPool;
//System.out.println(db.toString()); not remove the db.setName();
//this operation will print: [DBPool poolName]
}
}
}
<res-ref-name>jdbc/databaseName</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<init-param driver-name="oracle.jdbc.driver.OracleDriver"/>
<init-param url="jdbc:oracle:thin:@127.0.0.1:1521:databaseName"/>
<init-param user="username"/>
<init-param password="password"/>
<init-param max-connections="100"/>
<init-param max-idle-time="30"/>
</resource-ref>
写一个db.java文件import java.sql.*;
import com.caucho.sql.*;public class db { Connection c = null;
DBPool db = null;
public db() {
db = new DBPool();
} public Connection getConnection() throws SQLException {
if (c == null) {
return c = db.getPool("databaseName").getConnection();
}
else {
return c;
}
} public void clsConnection() throws SQLException { if(c != null) c.close(); //close Connection ;
if(db != null) {
/*if not setName(),the class will throw NullPointerException ,
*this is a bug in com.caucho.sql.* package maybe;
*System.out.println(db.toString());
*/
db.setName("poolName");
db.close(); //close DBPool;
//System.out.println(db.toString()); not remove the db.setName();
//this operation will print: [DBPool poolName]
}
}
}
解决方案 »
- 怎么通过XMLGregorianCalendar获得当前时间及当前时间的前十分钟的时间 ,就是获取两个时间点?
- 网页定时跳转遇到的问题
- 理想的编程语言
- java打包中的中文乱码问题,麻烦高手指点一下!
- struts显示层下拉列表的问题
- mybatis+spring查询分页问题
- java里怎么能取到%SystemRoot%的路径啊?
- 请问哪里有针对EJB存取数据的JDBC驱动程序?
- ****做个带有聊天功能的软件(类似QQ、MSN),大家帮忙测试一下,提点意见******
- 有没有人用JSF开发企业级的WEB应用程序?
- 高手交流,广开言路------------影响你入门的一本书
- 这个程序技术上是否可行
cannot be referenced from a static context
conn = dbpolltest.getConnection();
^
1 error
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<init-param driver-name="com.caucho.jdbc.mysql.Driver"/>
<init-param url="jdbc:mysql_caucho://localhost:3306/test"/>
<init-param user=""/>
<init-param password=""/>
<init-param max-connections="20"/>
<init-param max-idle-time="30"/>
</resource-ref>我没用过mysql,驱动应该在jdbc-mysql.jar中
Connection c = db.getConnection();用这样的方式获取连接
Connection c = dbconn.getConnection();上面写错了