Reputation: 575
from the Glassfish server log am getting an error below
WARNING: RAR8054: Exception while creating an unpooled [test] connection for pool [ hrms/connectionPool ], null WARNING: RAR8054: Exception while creating an unpooled [test] connection for pool [ hrms/connectionPool ], null
am getting a problem in implementing jdbc mysql datasource and connection pooling using jsp and struts framework. please help.
the code is shown.....
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package database;
/**
*
* @author LenasalonM01
*/
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.swing.JOptionPane;
public class database {
private Connection connect;
private Statement statement;
private ResultSet resultset;
private InitialContext context;
private DataSource datasource;
public void connection() {
try {
// load driver
Class.forName("com.mysql.jdbc.Driver").newInstance();
// initialize context
context = new InitialContext();
// datasource path
datasource = (DataSource) context.lookup("jdbc/hrms");
// connect to datasource
connect = datasource.getConnection();
// create statement from connection made
statement = connect.createStatement();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
public void disconnect() {
try {
if (resultset != null) {
resultset.close();
}
if (connect != null) {
connect.close();
}
if (context != null) {
context.close();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
public boolean checkValid(String query) {
try {
connection();
resultset = statement.executeQuery(query);
if (resultset.next()) {
return true;
} else {
return false;
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
return false;
}
}
public ResultSet fetchdata(String query) {
try {
connection();
resultset = statement.executeQuery(query);
disconnect();
return resultset;
} catch (Exception e) {
return resultset;
}
// return resultset;
}
}
Upvotes: 0
Views: 4653
Reputation: 309008
Is the MySQL daemon up and running? Can you connect to the server using the command line client? If not, start the server and re-run your application again.
I would advise you to separate your database code from user interface stuff. You'll regret combining the two the way you have someday.
Upvotes: 1
Reputation: 4181
Check that the jar containing the jdbc driver is library folder of your server
Upvotes: 0