How to make datasource connection IBP Session bean using JBoss3.0.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   zhi_chou
Posted On:   Saturday, April 6, 2002 03:05 AM

The source code of the session bean, which got datasouce connection, but error is can't find the session bean in my client. package ibs.util.ejb; import java.rmi.*; import javax.ejb.*; import java.sql.*; import javax.sql.*; import javax.naming.*; import java.util.*; public class AutoGeneratorEJB implements SessionBean { private SessionContext sessionContext; private Connection con; //private String dbName = "java:comp/env/jdbc/Oracle"; private String dbName = "java:/OracleDS"; private EntityContext context; public void ejbCreate() { } public void ejbRemove(){ } public void ejbActivate() {    More>>

The source code of the session bean, which got datasouce connection, but error is can't find the session bean in my client.
package ibs.util.ejb;

import java.rmi.*;
import javax.ejb.*;
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.util.*;

public class AutoGeneratorEJB implements SessionBean {
private SessionContext sessionContext;
private Connection con;
//private String dbName = "java:comp/env/jdbc/Oracle";
private String dbName = "java:/OracleDS";
private EntityContext context;
public void ejbCreate() {
}
public void ejbRemove(){
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) throws RemoteException{
this.sessionContext = sessionContext;
try {
makeConnection();
} catch (Exception ex) {
throw new EJBException("Unable to connect to database. " +
ex.getMessage());
}
}

public int findMaxId(String tableName) throws SQLException {
int maxNumber = 0;

/* String selectStatement =
"select max(ID)" +
"from ""+tableName+""";
*/
String selectStatement =
"select max(ID)" +
"from "+tableName;
PreparedStatement prepStmt =
con.prepareStatement(selectStatement);
ResultSet rs = prepStmt.executeQuery();

if (rs.next()) {
maxNumber = rs.getInt(1);
prepStmt.close();
}
else {
prepStmt.close();
System.err.print("Table " + tableName +
" not found in database.");
}
return maxNumber+1;
}
private void makeConnection() throws NamingException, SQLException {

//InitialContext ic = new InitialContext();
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL, "localhost:1099");

Context ctx = new InitialContext(props);
DataSource ds = (DataSource)ctx.lookup(dbName);
con = ds.getConnection();
}

}

   <<Less
About | Sitemap | Contact