数据库学习--wildfly配置postgreSQL数据源

前言

实验室最近在做一个物品管理系统的小项目,其中涉及到postgreSQL的使用,刚开始部署到wildfly服务器上时遇到了若干问题,终于在导师的讲解下大体上明白了 ,特此记录分享学习一下。

配置数据源的原因

为何要配置数据源,这点本人也就是心里明白,讲不出来也写不出来,只好以图说事了。话不多说,上图(日后再容我细细完善)。 
数据库访问管理理解图 
理解图

如何配置

wildfly下数据源的配置方法有两种。个人对于第二种方法实践过,只对第二种展开讲解,第一种给出参考材料。

配置方法一

配置文件配置法

参考材料:

http://dz.sdut.edu.cn/blog/subaochen/2013/08/jboss-as-7%E9%85%8D%E7%BD%AEpostgresql%E6%95%B0%E6%8D%AE%E6%BA%90%E7%9A%84%E6%96%B9%E6%B3%95/

配置方法二

wildfly命令行配置法,该种方法与上图可以一一对应起来,可以参考。

具体实现步骤:

a.下载postgreSQL JDBC driver并放到适合的目录下;

比如: 
driver

b.启动wildfly服务器;

命令:

./standalone.sh

bin

standalone

c.添加postgreSQL数据库到wildfly;

执行下列命令行(相应的driver的路径(加黑部分)改为自己的即可):

$ ./jboss-cli.sh

[standalone@localhost:9990 /] module add –name=org.postgresql 
–slot=main 
–resources=/home/gaoziqiang/devel/driver/postgresql/postgresql.jar 
–dependencies=javax.api,javax.transaction.api 
[standalone@localhost:9990 /] 
/subsystem=datasources/jdbc-driver=postgres:add(driver-name=”postgres”,driver-module-name=”org.postgresql”,driver-class-name=org.postgresql.Driver)

jboss

d.增加wildfly数据源;

继续在jboss-cli命令行下执行(替换为你的数据源名称、用户名和密码即可):

[standalone@localhost:9990 /] data-source add –name=labDS 
–jndi-name=java:jboss/labDS –driver-name=postgres 
–connection-url=jdbc:postgresql://localhost:5432/lab 
–user-name=postgres –password=666 –validate-on-match=true 
–background-validation=false 
–valid-connection-checker-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker 
–exception-sorter-class-name=org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter

配置成功的标志:

[standalone@localhost:9990 /] 
/subsystem=datasources:installed-drivers-list { “outcome” => 
“success”, “result” => [ { “driver-name” => “postgres”, 
“deployment-name” => undefined, “driver-module-name” => 
“org.postgresql”, “module-slot” => “main”, 
“driver-datasource-class-name” => “”, 
“driver-xa-datasource-class-name” => “”, “driver-class-name” => 
“org.postgresql.Driver”, “driver-major-version” => 9, 
“driver-minor-version” => 4, “jdbc-compliant” => false }, { 
“driver-name” => “h2”, “deployment-name” => undefined, 
“driver-module-name” => “com.h2database.h2”, “module-slot” => “main”, 
“driver-datasource-class-name” => “”, 
“driver-xa-datasource-class-name” => “org.h2.jdbcx.JdbcDataSource”, 
“driver-class-name” => “org.h2.Driver”, “driver-major-version” => 1, 
“driver-minor-version” => 3, “jdbc-compliant” => true } ] }

参考资料

资料一:http://dz.sdut.edu.cn/blog/subaochen/?s=Wildfly&submit=Search 
资料二:https://developer.jboss.org/wiki/GenericTypeCLICommands

总结

还有很多的不解,继续理解,继续分享。

原文地址:https://www.cnblogs.com/h2zZhou/p/8431904.html