This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes Can I create  connection pooling with data sources using sybase driver(jconn2.jar)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Can I create  connection pooling with data sources using sybase driver(jconn2.jar)?" Watch "Can I create  connection pooling with data sources using sybase driver(jconn2.jar)?" New topic
Author

Can I create connection pooling with data sources using sybase driver(jconn2.jar)?

Bhavani Kumar
Greenhorn

Joined: Feb 22, 2005
Posts: 15
Can I create connection pooling with data sources using sybase driver(jconn2.jar)? I am working on this for quite an amount of time but in vain. The exception raised is :

Exception in thread "main" java.lang.UnsupportedOperationException
at org.apache.commons.dbcp.PoolingDataSource.getConnection (PoolingDataSource.java:161)

My program looks like this :

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.commons.dbcp.ConnectionFactory;
import org.apache.commons.dbcp.PoolingDataSource;
import org.apache.commons.dbcp.PoolableConnectionFactory;
import org.apache.commons.dbcp.DriverManagerConnectionFactory;

public class ManualPoolingDataSourceExample {
public static void main(String[] args) {
String url = "jdbc:sybase:Tds:172.16.12.84:2048/lnk_common_dd";
System.out.println("Loading underlying JDBC driver.");

try {
Class.forName("com.sybase.jdbc2.jdbc.SybDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
System.out.println("Done.");
System.out.println("Setting up data source.");
DataSource dataSource = setupDataSource(url);
System.out.println("Done.");
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;

try {
System.out.println("Creating connection.");
conn = dataSource.getConnection("sa","");
System.out.println("Done.");
System.out.println("Creating statement.");
stmt = conn.createStatement();
System.out.println("Executing statement.");
rset = stmt.executeQuery("select * from testdata");
System.out.println("Results:");
int numcols = rset.getMetaData().getColumnCount();
while(rset.next()) {
for(int i=1;i<=numcols;i++) {
System.out.print("\t" + rset.getString(i));
}
System.out.println("");
}
} catch(SQLException e) {
e.printStackTrace();
} finally {
try { rset.close(); } catch(Exception e) { }
try { stmt.close(); } catch(Exception e) { }
try { conn.close(); } catch(Exception e) { }
}
}

public static DataSource setupDataSource(String connectURI) {
ObjectPool connectionPool = new GenericObjectPool(null);
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
return dataSource;
}
}

And i've placed all the necessary jars in the classpath ie :

commons-dbcp1.1.jar
commons-collections.jar
commons-pool1.2.jar
jconn2.jar
j2ee.jar
 
wood burning stoves
 
subject: Can I create connection pooling with data sources using sybase driver(jconn2.jar)?
 
Similar Threads
How to control no. of JDBC Connections in Tomcat!!!
Objects used to create a connection
Connection Pooling with Commons DBCP - spot the problem?
JDBC Connection Pooling Framework
Connection Pooling, anyone help me please!