问题
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