JDBC Connection

179 views
Skip to first unread message

kk

unread,
Nov 2, 2011, 5:59:17 AM11/2/11
to javamelody
I have a jsf application where connection is defined in a property
file. The format of the connection string is as follows

db.connection.connectionstring=jdbc:mysql://localhost/db?
user=user&password=password&allowMultiQueries=true

Inside the code I read this connection string and create the jdbc
connection and pool.

What configuration should I add to the configuration files to monitor
the jdbc info using Java Melody.

Thanks in advance



Emeric Vernat

unread,
Nov 2, 2011, 1:42:55 PM11/2/11
to javam...@googlegroups.com
Hi,

Can you give your java code which create the pool and the jdbc connections?
Then, I will try to give you the java code to monitor the jdbc info and
the sql requests.

bye,
Emeric


Le 02/11/2011 10:59, kk a �crit :

Emeric Vernat

unread,
Nov 5, 2011, 9:38:51 AM11/5/11
to javam...@googlegroups.com, kk
Hi,

Given that you use the DriverManager.getConnection directly to get a
jdbc connection as said below, the following should work to monitor the
jdbc connections and the sql requests:

Class.forName("net.bull.javamelody.JdbcDriver");
java.util.Properties info = new java.util.Properties();
info.put("driver", "com.mysql.jdbc.Driver");
info.put("user", user);
info.put("password", password);

Connection conn = DriverManager.getConnection(connectionString, info);

where connectionString is for example
"jdbc:mysql://localhost/db?allowMultiQueries=true"

bye,
Emeric


Le 03/11/2011 09:53, kk a �crit :
> Here we go. The connection is created like this
>
> if (ConnectionString == null || ConnectionString.length() == 0) {
> throw new SQLException("Connection string for '" +
> ConnectionName + "' is not configured.");
> }
>
> Connection conn =
> DriverManager.getConnection(ConnectionString);
> return new DbConnection(conn, this);
>
> The connection is created only when there are no connection object in
> the pool. Pool is implemented using arraylist. If the array lIst do
> not have any free connection, then a new connection is created.
>
> Regards
> KK

Reply all
Reply to author
Forward
0 new messages