最简单的用
局部数据库连接池
<Resource name="jdbc/mydb" type="javax.sql.DataSource" password="mypwd" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" maxIdle="2" maxWait="5000"
validationQuery="select1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb"
maxActive="4" />
局部数据库连接池
<Resource name="jdbc/mydb" type="javax.sql.DataSource" password="mypwd" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" maxIdle="2" maxWait="5000"
validationQuery="select1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb"
maxActive="4" />
解决方案 »
- hibernate中hibernate-extensions配置
- struts2 action传值
- hibernate 支持oralce数据库
- JSF页面跳转问题。
- 为什么说我提交参数有错误???????????
- jsp中设置了cookie的过期时间.为什么在客户端没有效果?
- linux服务器 apache占用内存问题。
- 有没有人懂工作流的?
- 各位谁在TOMCAT中做过连接池??50分请教
- 找不到Oracle驱动,该怎么办啊?请叫各位高手,在线等待!
- session失效后,spring拦截器应将用户请求的操作变为跳转到login.jsp页,但是ie里只是右侧的框架跳转了,不是整个页面跳转
- AxisFault问题:访问数据库时总是提示 faultString: java.lang.NullPointerException ?
Context env=null;
try{
env=(Context) new InitialContext().lookup("java:comp/env");
pool=(DataSource)env.lookup("jdbc/mydb");
if(pool==null){
throw new ServletException("mydb is an unknow DataSource");}
}catch(NamingException ne) {
throw new ServletException(ne.getMessage());}
}
Connection conn=pool.getConnection();
{
//数据库用户名
String userName="root";
//数据库密码
String userPassword="123";
//数据库的URL,包括连接数据库所使用的编码格式
String url="jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=utf-8";
//定义一个连接对象
Connection dbcon;
Statement stmt;
ResultSet rs;
/**
*@初始化操作,包括给变量赋初值和连接数据库
*/
public access_db()
{
//初始化参数值
stmt = null;
rs = null;
//连接数据库
try
{
//声明所用的类包
Class.forName("org.gjt.mm.mysql.Driver");
//获得数据库的连接对象
dbcon= DriverManager.getConnection(url,userName,userPassword);
}
catch(SQLException ex)
{
//打印出异常信息
System.out.println(ex.toString());
}
catch(ClassNotFoundException ex)
{
//打印出异常信息
System.out.println(ex.toString());
}
}
}