I need to encapsulate the database passwords inside the glassfish JDBCConnectionPool.
I found in glassfish documentation how to encapsulate user admin password.
Would anyone have an example of the encapsulation of database passwords?
browse http://localhost:4848
Click --> domains --> Password Aliases --> New
Add your connection pool password in password field and Click OK.
4.Create a connection pool.When creating connection pool fill the password filed
as below.
Example :
${ALIAS=[your_password_alias_name]}
${ALIAS=test_pwd_alias}
Start you GF server and go to the admin console (usually localhost:4848) :
Then go to Resources > JDBC > JDBC Connection pools.
Select your connection pool
Go to the Additional Properties tab
Here you will configure all your database connection info : username, database name, host (or database URL, depends on your DBMS), and password
Related
I have an application running on a server and I'm using H2 database for that,
This my database URL:
jdbc:h2:./cafeDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=7080
And I want to connect to this database using Intellj idea's database tools, this is my configuration:
But when I try to connect, It keeps asking me the DB's username and password, and even when I put the correct information and submit it says:
The specified database user/password combination is rejected: [28000][28000] Wrong user name or password [28000-200]
Am I doing something wrong?
I have a remote mysql database on mydomain.com power by goDaddy and have a database name "arsenal101" with several tables and I have assigned the user "arsenal101" with password "22216888" with full privilege to that database.
In my local MySQl workbench in Macbook, I try connecting my MySQL workbench to that remote database.
Here is the screenshot
The hostname I enter mydomain.com
The username is arsenal101
The password is 22216888
The default schema is blank.
After I pressed test connection, an error message showed up " Failed to Connect to MySQL at mydomain.com: 3306 with user arsenal101
access denied for user arsenal101#xxxxxxx (using password Yes)
You should check if GoDaddy allows you to do a remote connection to the database because a lot of hosting companies don't allow that. Their MySQL has to be configured to receive external connections.
According to here: https://in.godaddy.com/help/connect-remotely-to-databases-4978
If you want to connect remotely to a database, you must enable Direct Database Access when setting it up1 — you cannot enable it later.
I am frustrated seeing this error and not knowing the solution. I am trying to connect to a mysql db with a server url but it is giving my mysqlException(stacktrace below). The code works fine till here:
String dbUrl = "jdbc:mysql://server_url/db_name";
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver).newInstance();
String user = "user";
String password = "password";
conn = DriverManager.getConnection(dbUrl,user,password);
This is the error I'm getting
java.sql.SQLException: null, message from server: "Host '172.23.251.154' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1070)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
Is this because I'm using a different version of mysql-connector jar?
Please help me.
From Chapter 6. SQL Questions: How Do I Enable TCP Connections to MySQL?,
By default, MySQL won't allow ANY users access to any of the databases if they connect over a TCP connection. In order to permit the connection, you must create a entry in the user table of the mysql database (make sure you select the PASSWORD function to encrypt your password). In particular, the Host field needs to indicate which host(s) are permitted to connect. If you specify % (which I would not recommend), then a user would be able to connect from any host.
What about firewall on port 3306?
May be the user you are trying to access doesn't have enough privileges to access the database from the given server.
So try providing GRANTS to the user.
GRANT ALL PRIVILEGES ON database_name TO 'user'#'hostname' IDENTIFIED BY PASSWORD <password>;
FLUSH PRIVILEGES;
here hostname can be your host address "172.23.251.154". Dont forget to flush privileges and then try connecting the server.
If your MySql server is located on your host provider there is option in your control panel where you can set ip addresses from which you can connect to mysql server in your case 172.23.251.154 if this is your ip address
How can I configure persistence.xml file to connect to my SQL Server. Some information is connected as: Host, DatabaseName, UserName, Password, Port, ...
Setting up a connection pool to MySQL database using a configuration .xml file can be pretty troublesome to someone who has just started like you.
In my opinion, you should take a look at this short guide. You simply need to start Glassfish server, open the browser and surf to http://yourdomain.com:4848 to access the Admin panel. After that, just follow the instruction in that article and to create the JDBC Connection pool and JDBC Resource. At this point, you only need to open the persistence.xml file with your IDE (NetBeans, etc.) and set the Data Source property with name of your JDBC Resource and you're done.
One thing to note is that you must download the latest MySQL Connector/J and copy the file
mysql-connector-java-<version>-bin.jar
into the folder
<GlassFish-install-folder>\glassfish\domains\domain1\lib\ext
Otherwise, you will run into the expcetion Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource if you try to ping the database after creating the JDBC Connection pool.
First of all donwload jdbc driver for sqlserver and put that in glassfish lib directory and boot that.
Using Glassfish admin console:
define a jdbc connection pool and specify Host, DatabaseName,
UserName, Password, Port, ...
define a jdbc resource and select connection pool name that you have specified in step 1
then grab the name of jdbc resource and put it in your persistence.xml file : <jta-data-source>YOUR-JDBC-RESOURCE-NAME</jta-data-source>
and now you can connect to data base.
If you are using Netbeans, it has some nice wizards to produce connection pool and jdbc resource in glassfish.
Since you are using JEE6 this is another way using annotation:
import javax.annotation.sql.DataSourceDefinition;
#DataSourceDefinition(name = "java:app/env/myDatasource",
minPoolSize = 0,
initialPoolSize = 0,
className = "your.driver.class",
serverName="localhost",
user = "admin",
password = "admin",
databaseName = "test"
)
public class DbConfiguration {
}
For more info take a look at here.
I create a connection to a postgres 9 database using the stardard JDBC driver.
...
Connection myCon = DriverManager.getConnection("jdbc:postgresql://localhost/test?&user=test&password=test");
...
When I check the server status with PgAdmin and display all database sessions, I can see that the "Application Name" is not set for my Session. Is there a way to set the application name in the JDBC connection?
That is possible to set application name as connection parameter since Postgres JDBC 9.1dev-900:
Add support for setting application_name on both connection startup
and later through Connection.setClientInfo. (jurka)
ex: jdbc:postgresql://localhost:5432/DbName?ApplicationName=MyApp
or Connection.setClientInfo("ApplicationName", "My App")
For previous versions you could do this by setting application_name runtime parameter:
s.execute("SET application_name TO 'MyApp'");