首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Struts2.0+tomcat运用数据源

2012-10-31 
Struts2.0+tomcat使用数据源配置tomcat 数据源(conf\context.xml)resource namejdbc/mydata autndon

Struts2.0+tomcat使用数据源

配置tomcat 数据源(conf\context.xml)

<resource name="jdbc/mydata" autn="done"

?? type="javax.sql.DataSource"? maxActive="100" maxIdle="30"

?? maxwait="10000"? username="root" password="root"

?? driveClassName="com.mysql.jdbc.Driver"

?? url="jdbc:mysql://127.0.0.1:3306/mydata"

/>

?

在S2中引用数据源配置(web.xml)

<resource-ref>

<description>?DB connection?</desciption>

<res-ref-name>jdbc/mydata</res-ref=name>

<res-type>javax.sql.DataSource</res-type>

<res-auth>done</res-auth>

</resource-ref>

?

?

获取connection

public static Connection getDSConnection(){try{    InitialContext ctx = new InitialContext();    DataSource ds =(DataSource)ctx.loolup("java:comp/env/jdbc/mydata");conn = ds.getConnection();return conn;}catch (Exception e){  e.printStack();  System.err.println("DB ERROR!")  return conn; }}

?

?

?

热点排行