How to use Universal Connection Pool (UCP) with Sybase? - java

Trying to configure connection pooling in standalone Java application.
Using UCP and Sybase DB. I am stuck at Connection Factory ClassName to use for Sybase.
Tried using com.sybase.jdbc4.jdbc.SybConnectionPoolDataSource but with no success.

It's just like using a Connection from some props file, except you create a DataSource Object first, then retrieve your connection from the DataSource. I can't give you a better example than is in the Sybase documentation here...
Jconnect 7 (Jconn4) docs...Scroll to page 9

Related

how to implement sql server connection pooling in java jdbc?

I tried to search for this but it seems the answer might now be true anymore. How can do connection pooling in java with sql server? I found the new jdbc driver of microsoft but there's no sample code to show to use it.
Microsoft MSSQL-JDBC is now open sourced. You can see test cases used Hikari & Apache DBCP connection pool.
One can see PoolingTest.java and methods testApacheDBCP and testHikariCP.
For HikariCP and DBCP

Where exactly should JDBC URL value be changed?

I'm trying to run some application and get the following error:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for
JDBC]Can't start a cloned connection while in manual transaction mode.
I know that I should add the parameter ;SelectMethod=Cursor to your JDBC URL
But I'm having problem understanding where exactly should I change it? Should it be some conf file in JDBC driver folder somewhere? Or can I do it from sql management studio?
Also is there some easy way to determine if and what version of JDBC driver I have?
Help is very much appreciated!
You specify the URL when creating your JDBC connection, e.g.:
Connection con = DriverManager.getConnection(
"jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]",
username,
password);
Of course you have to replace the stuff in the brackets with your values.
Quite the same is true for every other tool (e.g. IntelliJ, Eclipse) I know of that connects to a DB via JDBC. See e.g. attached screenshot. Here you also specify the connection parameters via the JDBC URL.

JDBC Connection String with selectMethod=cursor breaks connection

I'm trying to deploy a JBoss webapp that requires selectMethod=cursor in the jdbc driver connection string.
But when I try connecting to my mssql (2008) database with this in the string, it just timesout when connecting. When I remove selectMethod=cursor from my connection string, it works/connects, but my app doesn't work and gives me this error: [SQLServer JDBC Driver]Can't start a cloned connection while in manual transaction mode.
I have already updated my jdbc driver - tested all versions.
Here is my connection string:
jdbc:microsoft:sqlserver://127.0.0.1:1434;DatabaseName=xxxx;user=xxxx;password=xxxxx;selectMethod=cursor
Thanks.
I switched from using a microsoft jdbc driver to jtds jdbc driver and it works wonderfully again.
Do the Microsoft docs on the issue shed any light on this?
This error occurs when you try to execute multiple statements against a SQL Server database with the JDBC driver while in manual transaction mode (AutoCommit=false) and while using the direct (SelectMethod=direct) mode. Direct mode is the default mode for the driver.
Resolution is:
When you use manual transaction mode, you must set the SelectMethod property of the driver to Cursor, or make sure that you use only one active statement on each connection as specified in the "More Information" section of this article.

MariaDB multiple masters in JDBC connection string

I am using MariaDB 5.5.38 and JDBC driver for MySQL. According to this article I should use connection string like
jdbc:mysql://address=(type=master)(host=master1host),address=(type=master)(host=master2host)/db
to use several master hosts. But when I use it I get NullPointerException in com.mysql.jdbc.NonRegisteringDriver.parseHostPortPair(NonRegisteringDriver.java:216) [mysql.mysql-connector-java-5.1.30.jar:na]. I also use connection pool from Apache Commons, but I think it's not relevant. So, what am I doing wrong?
Your link to this article describe a Master/Slave setup.
If you want multi master setup you can use this url:
jdbc:mysql:loadbalance://masterHost1,masterHost2/db
Read more about it here: Configuring Load Balancing with Connector/J
After browsing mysql-connector-j source code NPE is caused by a missing prefix on your connection URL. It should be one of the following:
jdbc:mysql:loadbalance//.....
jdbc:mysql:replication//.....
With this urls it seems only urls with //host:port,host:port/db work and only the first one is used as a master.
other thing to check is what Driver class are you using.
acording to this question: How do I configure our MySQL ReplicationDriver for our JBoss 7 data source?
the correct class is
com.mysql.jdbc.ReplicationDriver
I had the same problem and found the following:
https://bugs.mysql.com/bug.php?id=75440
I changed the connection url to:
jdbc:mysql://address=(protocol=tcp)(type=master)(host=serv1),address=(protocol=tcp)(type=master)(host=serv2)/db
this works for me so far

How to remove invalid database connection from pool

I am using connection pooling of tomcat with oracle database. It is working fine, but when i use my application after a long time it is giving error that "connection reset". I am getting this error because of physical connection at oracle server closed before logical connection closed at tomcat datasource. So before getting the connection from datasource i am checking the connection validity with isValid(0) method of connection object which gives false if the physical connection was closed. But i don't know how to remove that invalid connection object from the pool.
This could be because on the db server, there is a timeout to not allow connections to live beyond a set time, or to die if it does not receive something saying it is still valid. One way to fix this is to turn on keepalives. These basically ping the db server saying that they are still valid connections.
This is a pretty good link on Tomcats DBCP configurations. Take a look at the section titled "Preventing dB connection pool leaks". That looks like it may be a good place to start.
I used validatationquery while configuring the datasource in server.xml file. It is going to check the validity of the connection by executing the query at database before giving to the application.
for Oracle
validationQuery="/* select 1 from dual */"
for MySql
validationQuery="/* ping */"
Try closing it and opening it if it's invalid. I mean u would reinitialize it in this way so u won't need to remove it from the pool and reuse it.
If we want to dispose an ill java.sql.connection from Tomcat jdbc connection pool,
we may do this explicitly in the program.
Unwrap it into an org.apache.tomcat.jdbc.pool.PooledConnection,
setDiscarded(true) and close the JDBC connection finally.
The ConnectionPool will remove the underlying connection once it has been returned.
(ConnectionPool.returnConnection(....))
e.g.
PooledConnection pconn = conn.unwrap(PooledConnection.class); pconn.setDiscarded(true);
conn.close();

Categories

Resources