I'm developing a simple web application with spring boot. In the first step, I implemented everything about the page itself and a simple login. Additionally, I implemented a database access using mysql and hibernate. My database runs on a local easyphp devserver.
In the first step, everything worked fine. However, after a reset of the database and recreating the user with the same credentials, Hibernate is not able to get a connection:
2018-02-09 21:17:11.487 ERROR 9592 --- [ restartedMain] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''#'localhost' to database 'db'
As I can understand, no username was configured. But in my application.properties, a username is set:
spring.datasource.url=jdbc:mysql://localhost:3306/db?userSSL=false
spring.datasource.username=user
spring.datasource.password=
The exception occurres on startup, so it has to be the configuration. At the database, the user 'user' has all priviliges at the database 'db', but no one on others.
The data source URL might be causing the issue. Is that a typo? Can you check by resetting it to the following? It has to be "useSSL" instead of "userSSL"
spring.datasource.url=jdbc:mysql://localhost:3306/db?useSSL=false
spring.datasource.username=user
spring.datasource.password=
If the above does not work, your problem might be related to permissions for the user. A question posted here relates to yours (although it is in PHP).
Hopefully this resolves it, let us know.
Ok, found the solution by myself. The real username contained a '_' like 'user_name'. Somehow this character was the problem why the username was not read.
Edit: Worked a few times, but the problem still exists...
Related
hope you can help me with an weird issue I'm facing in a project.
I'm running over a Java app that is currently running with Eureka, MyBatis, DB2 as database & Druid datasource.
We have a DB2 URI to configure the database connection, in that one, we are setting up the currentSchema:
jdbc:db2://localhost:8081/MYDB:currentSchema=MYSCHEMA;charSet=UNICODE;
As you can see in the before URI connection, we are passing directly the currentSchema in which we wants to work.
In addition, we are passing the username & password as spring properties due we are using Druid Datasource:
spring.datasource.username=MYUSERNAME
spring.datasource.password=MYPASSWORD
When I deploy the app, everything runs correctly, the database connects to MYSCHEMA.AnyDBTable, however, by any reason that really I'm not understanding, some times, by any reason, the currentSchema, is replaced with the username MYUSERNAME.AnyDBTable, we have been spending time trying to figure out why is happening that, we have reviewed our code a lot of times trying to see if, in any place our code is doing the replace, however we are sure that is not happening from our code.
As you could figure out, that causes issues when trying to get info from DB because MYUSERNAME.AnyDBTable does not exist.
we are using the below dependency in our project for DB2:
[INFO] | +- com.ibm.db2:jcc:jar:11.5.5.0:compile
Any idea guys why could be happening that?, any help will be well received.
NOTE: we validated the .properties files living on eureka server, and the currentSchema is not modified, it is as we defined it initially, after reseting the whole app, it works correctly again.
I am surprised I haven't found an SO question that answers this. I am trying to connect a springboot/JPA application to an SQL Server on my local machine. I have the application setup so that it can connect to a database if it it exists, but if I change the JDBC URL to create the database if it doesn't exist then it fails. Here is what the properties look like when it fails.
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=testing;createDatabaseIfNotExist=true;
spring.datasource.username=hello
spring.datasource.password=Hello1234
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.database-platform=org.hibernate.dialect.SQLServer2008Dialect
spring.jpa.show-sql=true
Here is a snippet of the error I receive when starting the app:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user
'hello'. ClientConnectionId:971a3369-258b-4713-bddc-cda559b9fe94 at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
~[mssql-jdbc-8.4.0.jre11.jar:na] at
com.microsoft.sqlserver.jdbc.TDSTokenHandle
If anybody has any thoughts as to how I can change this so the database is created if it does not exist I would be very thankful. Thanks in advnace.
I don't think a database can be created using JPA.
It has to be created manually or in some other ways, but JPA won't do that for you.
And it would be a bad practice as well to create the database using the application itself, and the use of same credentials.
Yes, definitely you can auto-create a database with JPA for that
spring.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=testing;
createDatabaseIfNotExist=true;
line should be changed to:
spring.datasource.url=jdbc:sqlserver://localhost:1433
/testing?createDatabaseIfNotExist=true
In practice your application should never create your database so its not really a problem most of the time(Outside small databases like sqlite3). Different databases would handle this situation differently as well.
In your case I do not see this as a valid jdbc parameter in the documentation.
I would recommend creating the database in advance with a privileged user separate from your application user.
I am trying to learn MongoDB with Spring. When I try to write to the db it works but everything goes to the test database. Here is how my application.properties file looks like:
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.username=
spring.data.mongodb.password=
spring.data.mongodb.database=pets
The records are supposed to go to the database pets, but they all go to test. Any idea why? I have no other configurations. Even when I comment out all those settings, it still works and writes to test, which makes me think that they are just being ignored. I have no password and username set up.
Thanks
For some reason, I solved it by defining a MongoConfig and setting the database name there. Apparently, it is deprecated, but it works...
Currently in my spring boot application.properties file, I am specifying following lines to connect to MSSql server.
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=springbootd
spring.datasource.username=sa
spring.datasource.password=Projects#123
Instead of giving username and password, I want to authenticate user using kerberos, what all changes I will have to make.
I tried searching in the JPA official documentation but could not find any. Leads here are appreciated.
Basically, you need to set up your krb5.conf file properly. You can verify that configuration via the following command and entering your password:
kinit <user-name>
Additionally, make sure you have a JDBC URL like:
jdbc:sqlserver://servername=server_name;integratedSecurity=true;authenticationScheme=JavaKerberos;userName=user#REALM;password=****
See Microsoft JDBC driver documentation for details.
EDIT:
Forgot to mention the startup arguments. Add the following JVM argument:
-Djava.security.krb5.conf=<PATH_TO>/krb5.conf
I believe this is not neccessary if you use the default krb5.conf but not entirely sure.
In my J2EE 5 application I have a JDBC Realm based security with Form method. Encrypt method is MD5 as default.
The database is PostgreSQL 8.4 installed locally (or 8.3 available via lan).
My app used to work finely on GlassFish v2.1 server with PostgreSQL 8.3, but now I need to deploy it on GlassFish v3.
I am absolutely sure I have done all the same config on GFv3 like creating Connection Pool (which pings with no problem), JDBC Resource and JDBC Realm.
But on GFv3 I get login exception with "invaliduserreason" while the database schema is just created from the working database script.
I have checked the data and entered login/password thousand times and it seems that data is all right.
So where can I find the reason of unworking security? Please, advice.
NetBeans 6.8
Thanks.
I had the same issue here.
I resolved setting the security log to finest.
I saw that jaas was querying the db in lowercase even though I used a camel notation in naming my fields in postgresql table.
The only solution I found was to name all my table and fields in lowercase in Postgresql server as well.
You might want to increase the logging for the security system. Go to Logger Settings -> Log Warnings and set logger name 'javax.enterprise.system.core.security' to trace. Try again and check the logs.
Try changing database tablenames to UPPERCASE. I had the exactly same problem as you have and changing tablenames to uppercase solved the problem for me.
Setting Digest Algorithm to "none" worked for me. I am using Glassfish 3.1 with Derby. In realm config i have name of tables in lowercase and userid and groupid are columns in the same table, so these things do not cause problems on Derby.
Here is a nice article about jdbc security realm in glassfish and how to configure it: http://jugojava.blogspot.com/2011/02/jdbc-security-realm-with-glassfish-and.html
try adding database name to the property Url in your connection pool.. the sqlexception hidden here states that database name is not specified.. worked for me