connecting hsql thru stateless session bean
yajbossuser Nov 17, 2003 10:03 AMhi
plz tell me how to use a hsql database using a stateless session bean. plz give me link to some tutorial or sample code.
i tried the foll code which works with jboss 2.2.2 but not with jboss 3.2.2:
import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.*;
import javax.rmi.*;
import java.sql.*;
import java.util.*;
import java.io.*;
import javax.naming.*;
/**
It includes empty method bodies for the methods
prescribe by the SessionBean interface; these don't need to do
anything in this simple example.
*/
public class JDBC_ExampleBean implements SessionBean
{
Connection c = null;
Statement st = null;
Statement st2 = null;
public void welcome()
{
String query="";
String type="";
try
{
getConnection();
st = c.createStatement();
st2 = c.createStatement();
/* try
{
ResultSet res3 = st.executeQuery("select bearing_type_id from demands_table");
while(res3.next())
{
type = res3.getString(1);
System.out.println("type "+type);
}
}catch(Exception e){System.out.println(e.getMessage());}*/
}
catch(Exception e)
{
System.out.println("Exception occured");
System.out.println(e.getMessage());
}
}
/**
Perform any initialization your bean needs
*/
public void ejbCreate() {
System.out.println("EJB is created");
}
/**
Empty method body
*/
public void ejbRemove() {
System.out.println("EJB is removed");
}
/**
Empty method body
*/
public void ejbActivate() {}
/**
Empty method body
*/
public void ejbPassivate() {}
/**
Empty method body
*/
public void setSessionContext(SessionContext sc) {}
public void getConnection()
{
try
{
Class.forName("org.hsql.jdbcDriver");
c = DriverManager.getConnection("jdbc:HypersonicSQL:hsql://localhost:1476","sa","");
// c = DriverManager.getConnection("jdbc:HypersonicSQL:hsql://10.109.13.7:1476","sa","");
c.setAutoCommit(false);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
I get the following exception on server side:
INFO [STDOUT] EJB is created
INFO [STDOUT] No ClassLoaders found for: org.hsql.jdbcDriver
INFO [STDOUT]Exception occured
INFO [STDOUT]null