欢迎加入站点基地设计开发交流群:30720409
详细内容
jsp连接数据库,其他页面包含连接数据库文件
发布日期:2010-03-17     点击:3698     字体:[ ]

定义一个连接数据库文件conn.jsp:

<%
Class.forName("com.mysql.jdbc.Driver").newInstance();    
String   dsn="jdbc:mysql://localhost:3306/test_db?user=root&password=sa&useUnicode=True&characterEncoding=GB2312";    
   
Connection   conn=DriverManager.getConnection(dsn);    

%>

 

其他页面可以通过在页面顶部包含:

<%@ include file="conn.jsp"%>

在页面内容中即可直接引用conn建立数据库连接,例如

<%

Statement   cmd=conn.createStatement();

%>

用户评论
昵称:aa 来自:120.202.106.*  
2013-4-20 21:38:09
jsp
昵称 
内容  *
验证码   
   
相关文章 更多...  
Copyright © 2010 zdbase.com All Rights Reserved. 苏ICP备15039389号-1 可人软件设计