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.
Related
I try to use the MongoDB in the spring-boot project.
I tried a different of non-usable tutorial and stopped on the official documentation
I created cluster and now I ready to use MongoDB in my project.
Documentation says:
As I understand the pwd - this is the password, so my application.properties looks like:
spring.data.mongodb.uri=mongodb+srv://root:pass#88.155.XX.XXX.mongodb.net/mygrocerylist
spring.data.mongodb.database=mygrocerylist
this is all what I added to the application.properties - there are no other information in the tutorial.
After I started project, I receive error, that repeats every several seconds (however project still launched - I receive error even during system logging):
com.mongodb.MongoConfigurationException: No SRV records available for
host 88.155.21.126 at
com.mongodb.internal.dns.DefaultDnsResolver.resolveHostFromSrvRecords(DefaultDnsResolver.java:64)
~[mongodb-driver-core-4.4.2.jar:na] at
com.mongodb.internal.connection.DefaultDnsSrvRecordMonitor$DnsSrvRecordMonitorRunnable.run(DefaultDnsSrvRecordMonitor.java:78)
~[mongodb-driver-core-4.4.2.jar:na] at
java.base/java.lang.Thread.run(Thread.java:829) ~[na:an]
please, can anyone to explain how to exactly add MongoDB to the spring project?
I prefer to use such solution, since I need to complete the task and launch my project in the another PC. In any case - I tried to use mongoDb in the docker and this way also not work for me, and I not sure the other side use MongoDB locally.
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.
So I have a maven / spring application running on tomcat 8. I'm playing around with storing the sessions in dynmao db. There are a few reasons why I want to do this but i'll spare you the details.
I've been following this guide pretty religiously https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-tomcat-session-manager.html#java-dg-tomcat-sess-manage-with-ddb but my data does not seem to be being sent to the dynamoDB table I set up.
So what i've done.
First I downloaded this jar:
aws-dynamodb-session-tomcat-2.0.4.jar
and moved it to my lib folder.
Then I set up my context.xml like:
className="com.amazonaws.services.dynamodb.sessionmanager.DynamoDBSessionManager"
awsAccessKey="mykey"
awsSecretKey="mysecertKey"
regionId="us-east-1"
createIfNotExist="true" />
These apps are on EC2 instances so I skiped the ECB step. Next I set up a DBB table that looks like:
Table name Tomcat_SessionState
Primary partition key sessionId (String)
But when I restart my app and try and login I don't see anything geting posted there..
I've been tailing my catalina.out but no luck there either. Another note on this I don't see anything about DBB in my catalina.out strange.
Am I missing a common step here?
UPDATE:
When I start my app it creates the needed table. Just can't seem to get it to send the session id's out there. I wonder if a code change needs to be made to support this feature? I thought it supported any forum of sessions.
Edited by: dennis93 on Mar 8, 2018 2:13 PM
I see something like this in my log:
dynamo-session-manager-expired-sesion-reaper
Dynamo DB Tomcat Session Management Support is dropped. Ref: https://forums.aws.amazon.com/thread.jspa?threadID=275425
When I was experimenting with the AWS DynamoDB session manager, I experienced an unexplainable effect where writes of session data into DynamoDB would ONLY occur if the Manager is declared inside the global context.xml, i.e. within $CATALINA_HOME/conf/context.xml
The data has to be written to your DynamoDB table in order to persist across tomcat process restarts.
Was wondering, what steps am I missing to get a jdbc embeded h2 database working in my play application? Following these docs.
So far editted Application.conf file to contain this:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:databases/test"
db.default.user=test
db.default.password="testtest"
Next I created a libs directory and added the jar file
h2-1.3.174.jar
Is this necessary or does the provided driver handle all types of h2 databases (embeded and server - I know it handles in memory)?
Now in the controler how can I access the database? Do I have to start/shutdown the database?
I know I can get connections from the getConnection() method in play.db. But everytime I execute a statement through this connection I get an exception saying no data is available. If I then check - looks like directory
databases/test
was not created so no database files exist.
What am I missing?
H2 works out of the box. Just create a new project in the terminal.
Otherwise, to your listing:
I think you should change db.default.url="jdbc:h2:databases/test" to db.default.url="jdbc:h2:mem:play"
don't need to create lib directories. It's all handeled by the build in dependency mgmt sbt
Just use the model objects and call save/update. No need to call start/shutdown
you are in a framework, it's all there ready for you...
I think you should start reading the documentation from the beginning to the end and examine the example applications. It's all there what you are looking for.
In addition to myborobudur's answer I'll only mention, that you don't need to use memory database, as you can for an instance use file storage (Embedded) or even run H2 as a server and then connect to it with TCP in Server Mode... Everything is clearly described in H2 documentation.
I'm trying to deploy an application to my GlassFish Server environment. I've set it up so that GlassFish creates a connection pool to a postgreSQL database on another server (not localhost) where the database is located. I test the connection and then try to deploy the application. It fails with a java.lang.RuntimeException: EJB Container initialization error, and my error log contains the following: http://ideone.com/UlZXut (put it here due to its size). There were other warnings above these, but they only referred to tables already existing.
As according to this, I thought that the required sun-cmp-mappings.xml file (the one I assume would be necessary for this correct mapping) would be automatically generated upon deployment, but it seems I was wrong. Could anyone shed some light on this situation?
My apologies if this is not the absolute best part of SE to post this, but it is related to development tools and I did see a number of related posts.
Your error log indicates that you are trying to create table(s) with DOUBLE as a datatype. In Postgresql, that datatype is actually called "double precision". What happens if you revise the table definition to use "double precision" instead?
on startup Glassfish tries to create the DB tables for your java code. It fails to do that and it fails to startup.
Check the configuration of your ORM mapper.