最代码官方
2020-03-12 11:11:00
java web项目中IntelliJ IDEA配置tomcat的mysql的数据源连接教程
在java web开发中,经常通过在tomcat的Context中配置数据源javax.sql.DataSource来实现获取数据库连接对象,在eclipse中可以直接找到tomcat的server.xml,添加Context就能实现,但是idea下没有这个配置,但是可以通过其他方式实现,步骤如下
1.右键点击项目,然后选择Open Module Settings
2.选择Facets选项后,点击Add Application Server specific descriptor
3.选择Tomcat Server
4.idea会自动在Web Resource Directory的META-INF目录下生成默认的context.xml,只要添加自己的数据库连接配置就可以
<Context> <Resource name="jdbc/db" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="zuidaima" password="111111" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1:3306/zuidaima_www?useunicode=true&characterEncoding=utf8"/> </Context>
评论
最近浏览
hihhhh LV6
2023年4月6日
全栈小白 LV34
2023年1月8日
youwuzuichen LV10
2022年5月27日
PangPanda
2021年12月8日
暂无贡献等级
xiaofeiqwe
2021年10月18日
暂无贡献等级
最代码-宋家辉 LV61
2021年5月16日
quyiwen LV1
2021年5月11日
raoqichen LV1
2021年5月5日
Zeorwyc LV8
2021年3月11日
Ma2020 LV6
2021年3月10日