How can I create a mysql connection pool using asadmin tool in GlassFish server?

偶尔善良 提交于 2019-12-22 05:15:33

问题


I am trying to use the following command to create a mysql connection pool in GlassFish but it keeps telling me Command create-jdbc-connection-pool failed. Please help me. The command:

asadmin create-jdbc-connection-pool \
--datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource \
--restype javax.sql.DataSource \
--property "User=root:Password=...:URL=jdbc\:mysql\:\/\/localhost:3306\/wcms_3" \
connection_pool

I guess that there is a missing required parameter; so what are the required parameters needed if my guess was true?


回答1:


Maybe it's a typo but referring to this blog only the URL-part of the --property has to be surrounded by double quotes, such as:

asadmin create-jdbc-connection-pool
        --datasourceclassname oracle.jdbc.pool.OracleDataSource 
        --restype javax.sql.DataSource 
        --property user=dbuser:password=dbpassword:url="jdbc\\:oracle\\:thin\\:@localhost\\:1521\\:ORCL" oracle-pool

Furthermore notice the use of escape characters in this example.




回答2:


Check out this blog post:

  • he uses the pooled datasource (which IMO is necessary)
  • check the escaping of the --property string.

Alternatively, to circumvent escaping woes have a look here:

 --property user=root:password=test:DatabaseName=test:ServerName=localhost:port=3306

ie, specify the connection without using a JDBC URL.




回答3:


use following command for mysql connection pool using asadmin utility glassfish

[glassfish installation dir]/bin/asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource --restype javax.sql.DataSource --property User=[db_username]:Port=3306:Password=[db_password]:Url="jdbc:mysql://[localhost or ip]:3306/[db_name]" [pool_name]

db_username is your database username

db_password is your database password

db_name is database name

pool_name is anything that you want

example

./asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource --restype javax.sql.DataSource --property User=admin:Port=3306:Password=admin:Url="jdbc:mysql://127.0.0.1:3306/\test" test_pool




回答4:


Following two things has solved the same issue for me. They are:

1) use \ only for glassfish escape characters

2) try giving the command in a single line, for example

create-jdbc-connection-pool --datasourceclassname=org.apache.derby.jdbc.ClientDataSource --restype=javax.sql.DataSource --property portNumber=1527:password=APP:user=APP:serverName=localhost:databaseName=sun-appserv-samples:connectionAttributes=\;create\\=true SamplePool


来源:https://stackoverflow.com/questions/6572895/how-can-i-create-a-mysql-connection-pool-using-asadmin-tool-in-glassfish-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!