I have a query. My application is deployed using WebLogic server, where a JDBC data source is configured. The application config file is configured to pick up the JNDI name and make connectivity to connection pool at application startup. When there is no network connectivity, it fails to resolve the JDBC data source. On resuming network connectivity, we have to restart the server in order to get the JDBC data source working.
Is there any way to dynamically enable JDBC data source in WebLogic or to resolve it after a network failure once connectivity is back instead of restarting the server?
Weblogic does it automatically if you set the "initial connection" to 0 in Datasource connection pool. But you have to rewrite your application to periodically check, if the datasouce is UP or DOWN.
Related
I'm using UnboundID LDAP SDK for Java to query Active Directory using LDAP.
I'm creating the connection every time now so I'd like to change my code to use connections pool. I've found some examples how to create a connections pool, how to get and return the connection (link). I plan to do so using spring components on Mule ESB server but I'm worried about opened connections after my server or AD server restarts or communication problems.
How can I:
prevent my code from opened connections after my server restart
reconnect, recreate connections after AD communications problems
I am building an app using Spring Boot with MSSQL. For connection pooling I am using Tomcat JDBC.
My question what happens to the connection pool when a database is taken offline for a few minutes and what is the best way to recover from this database going offline.
I have tried the following tomcat connection pool configuration and when the database was taken offline and then brought online new connections were not established. I keep gettin the exception com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
Tomcat JDBC Configuration:
primary.datasource.tomcat.testWhileIdle=true
primary.datasource.validationQuery=SELECT 1
primary.datasource.validationInterval=34000
primary.datasource.initial-size=10
primary.datasource.max-active=50
primary.datasource.max-idle=20
primary.datasource.min-idle=10
primary.datasource.timeBetweenEvictionRunsMillis=34000
primary.datasource.minEvictableIdleTimeMillis=55000
primary.datasource.removeAbandoned=true
primary.datasource.removeAbandonedTimeout=55000
Please note that I have two datasources configured
I am using h2 in my spring application on runtime mode
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
I was able to insert and pull data (using postman) but I want to see the database myself and explore the schemes and data
I'm using Intellij
I've installed H2 Client http://www.h2database.com/html/main.html
and browse via sa and blank password (don't understand why the password is blank nor how do I changed it)
where are my tables? am I connected to the right instance?
UPDATE
I see that when I stop my Spring application, I'm still being able to browse to H2 via H2 console, I was expecting it will be offline... I don't get it
If you are using in-memory h2 database then use below JDBC url.
jdbc:h2:mem:testdb
Check the configuration provided at post How to connect H2 console to embedded Spring H2 DB
I found that I could only do this when I used a file database.
url: jdbc:h2:~/nexin;DB_CLOSE_DELAY=-1;MODE=MySQL;MV_STORE=FALSE;MVCC=FALSE
I was using dbVizualizer not Intelij.
As H2 documentation says:
The following connection modes are supported:
Embedded mode (local connections using JDBC)
Server mode (remote connections using JDBC or ODBC over TCP/IP)
Mixed mode (local and remote connections at the same time)
To be able to simply connect to a database from two separate applications, the connection mode should be Server Mode or Mixed Mode (read h2 documentation for further information). The mode you are using is determined by the connection url you use to connect to it and in your case the connection url is jdbc:h2:~/test which means that you're starting H2 in an Embedded Mode. This means that the database server will be started from within your application and will be accessible only to that single JVM.
TLDR
You can simply change the mode to Mixed mode using Automatic Mixed-Mode feature. To do so, just change your jdbc url (in both applications - your app and the client app) to: jdbc:h2:~/databasefile;AUTO_SERVER=TRUE.
This ~/databasefile is a location of where actual data will be stored - again, it is important to access the same file for both connections/applications.
If you're using Spring Boot with default configuration, to change the jdbc url you just have to add following property:
spring.datasource.url=jdbc:h2:~/databasefile;AUTO_SERVER=TRUE
I have a JSP web application deployed on a Weblogic server connected to an Oracle Database. There is no datasource set in the weblogic server instance and the application communicates with the database on it's own (with jdbc). However, every morning when I try to access the web page I get a 'No more data to read from socket' error. I reset the weblogic server and everything gets back to normal, but the thing is I can't keep restarting the server every morning.
Is there anyway that this can be fixed automatically? I think it has something to do with the connections in the pool, probably being disabled by oracle but still considered active by the application...
Thanks
I did manage to get this corrected.
What I did was creating a datasource in the Weblogic admin console and then configure my app to use this datasource. It was still giving the error initially but then I unchecked the "Keep Connection After Local Transaction" box from the datasource transaction options and this fixed the problem.
I'm looking for a way to pass web-application transaction information on to the underlying database process. In my Java code I might have a transactional method ReservationService#search(), which runs one or several SQLs. On the DBMS I just see a SPID along with some locks. I'm looking for a way to add a tag "ReservationService#search" to the database process.
jTDS / Sybase ASE have an appName which can be passed in as a connection property. As we're using a connection pool, existing connections are re-used, but to my knowledge the appName is only read on establishing a new connection.
How can I re-set the appName on an already existing connection (without closing/opening)? Or, if that simply is impossible, are there any other ideas to get transactional context information from Java to the DBMS?
Tomcat Webapplication (Java 6)
C3P0 Connection Pool (only supports JDBC 3)
jTDS connecting to Sybase ASE 15
Thanks
Simon
Unfortunately not, it seems that you can only specify that in the URL parameters when you open up the connection but can't be altered afterwords.
You can aways pass in a SessionID of some kind from your Java/Tomecat to all your Sybase queries. For me, this was easy as I use stored procedures for all communications between my Java application and the SQL server. I based my SessionID in Java on the J2EE session.