General discussion

Locked

*** Connection Pooling In JSP ***

By anand75 ·
hi ,
i downloaded DDCOnnetionBroker.jar package from http://opensource.devdaily.com
the program SimpleSample.java
works perfectly fine as a standalone program.
i am using RedHat8, Mysql 4 and Tomcat 4. i want to use this ConnectionPooling method for a JSP file. can anyone help me.
Here is the code for SimpleSample.java which works fine.
****************
CODE STARTS HERE
****************
import com.devdaily.opensource.database.DDConnectionBroker;
import java.sql.*;

public class SimpleSample
{

String driver = null;
String url = null;
String username = null;
String password = null;
int minConnections = 0;
int maxConnections = 0;
long timeout = 0;
long leaseTime = 0;
String logFile = null;
DDConnectionBroker broker = null;


/**
* The main() method gets called first, and it just calls the constructor.
*/
public static void main(String[] args)
{
new SimpleSample();
}


/**
* This method sets the parameters that will be used to construct
* the DDConnectionBroker.
*/
void setUp()
{
driver = "com.mysql.jdbc.Driver";
url = "jdbc:mysql://localhost/anand";
username = "";
password = "";
minConnections = 10;
maxConnections = 100;
timeout = 100;
leaseTime = 60000;
logFile = "c:/temp/DDConnectionBroker.log";
broker = null;
}


/**
* The constructor, where all the action starts.
*/
public SimpleSample()
{
setUp();

try
{
// construct the broker
broker = new DDConnectionBroker(driver,
url,
username,
password,
minConnections,
maxConnections,
timeout,
leaseTime,
logFile);
}
catch (SQLException se)
{
// could not get a broker; not much reason to go on
System.err.println( se.getMessage() );
System.err.println( "Could not construct a broker, quitting." );
System.exit(-1);
}

Connection conn = null;
try
{
// get the connection from the broker
conn = broker.getConnection();

// try to use the connection (it should work just fine)
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("SELECT uid, username, password, email FROM user");
while ( rs.next() )
{
int uid = rs.getInt( "uid" );
String theUsername = rs.getString( "username" );
String thePassword = rs.getString( "password" );
String theEmail = rs.getString( "email" );
System.out.println( "Database record: "
+ theUsername + ", "
+ thePassword + ", "
+ theEmail );
}
}
catch (SQLException se)
{
System.err.println( "ouch, threw an SQLException: " + se.getMessage() );
}
finally
{
try
{
broker.freeConnection( conn );
}
catch (Exception e)
{
System.err.println( "Threw an exception trying to free my Connection: "
+ e.getMessage() );
}
}
}

}

****************
CODE ENDS HERE
****************

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Desktop Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums