Here is the code . I am inserting comment as it is as im not getting the error.
Thanks .
Code :
public
String getMaxPrimaryValue(String TableName, String preffix)
throws com.next.analysis.exceptions.TableNotFoundException {
try {
column = "";
table = TableName.toUpperCase();
/*
AnalysisContext context = new AnalysisContext();
java.sql.Connection conKet = context.getConnection();
ResultSet rsKet = conKet.getMetaData().getPrimaryKeys("", "EJSADMIN", table);
if (rsKet.next()) {
System.out.println(" Table Name : " + rsKet.getString("TABLE_NAME"));
System.out.println(" PK Name : " + rsKet.getString("PK_NAME"));
System.out.println(" Column Name : " + rsKet.getString("COLUMN_NAME"));
System.out.println(" Schema Name : " + rsKet.getString("TABLE_SCHEM"));
table = rsKet.getString("TABLE_NAME");
column = rsKet.getString("COLUMN_NAME");
} else {
System.out.println("There is no record in Result Set.");
}
ResultSet rsKet = null;
sql = "SELECT " + column + " FROM " + table;
psKet = conKet.prepareStatement(sql);
rsKet = psKet.executeQuery();
int idOne = 0;
int idTwo = 0;
int last = 0;
while (rsKet.next() != false) {
preffix = rsKet.getString(1).substring(0, 1);
idOne = Integer.parseInt(rsKet.getString(1).substring(1));
System.out.println("ID : " + idOne);
if (rsKet.next()) {
idTwo = Integer.parseInt(rsKet.getString(1).substring(1));
} else {
last = idOne;
}
if (idOne > idTwo) {
last = idOne;
} else {
last = idTwo;
}
idOne = last;
idTwo = last;
} //end while
last = last + 1;
System.out.println("Max Value " + last);
preffix = preffix + last;
if (rsKet != null)
rsKet.close();
if (psKet != null)
psKet.close();
if (conKet != null)
conKet.close();
return preffix;
*/
return "F10001";
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
return null;
}
Here is AnalysisContext Class ::::
public class AnalysisContext {
private java.sql.Connection conn = null;
private javax.naming.Context ctx = null;
public AnalysisContext() {
super();
}
public java.sql.Connection getConnection() throws java.sql.SQLException,java.lang.Exception {
try {
if(conn == null){
javax.naming.Context jndiContext = getInitialContext();
DataSource ds = (DataSource) jndiContext.lookup("jdbc/ORANTNEW");
System.out.println("Got the Connection");
this.conn = ds.getConnection("ejsadmin","ejsadmin");
}
return conn;
} catch(Exception ne) {
System.out.println("Exception in getConnection");
throw new javax.ejb.EJBException("Exception in getHome" +ne.getMessage());
}
}
public Object getHome(String name, Class type) throws java.lang.Exception {
try {
System.out.println("Me in getHome");
javax.naming.Context jndiContext = getInitialContext();
System.out.println("got jndiContext" + jndiContext);
System.out.println("Going to call lookup");
Object ref = jndiContext.lookup(name);
return javax.rmi.PortableRemoteObject.narrow(ref,type);
}
catch (Exception ne) {
ne.printStackTrace();
throw new javax.ejb.EJBException("Exception in getHome" +ne.getMessage());
}
}
public javax.naming.Context getInitialContext() throws javax.naming.NamingException {
System.out.println("Me in Context.getInitialContext");
if(this.ctx==null){
java.util.Hashtable env = new java.util.Hashtable();
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
env.put(javax.naming.Context.PROVIDER_URL,"IIOP://localhost:900/");
this.ctx = new javax.naming.InitialContext(env);
System.out.println("Context "+ctx);
}
return ctx;
}
}
In the above code I m confirm tht im getting error somewhere connection only. As i hd previously mentioned without calling the entity i am getting the max value perfactly.And if I am calling entity , and when container calls ejbstore() after that only it gets Rolledback exception.The problem is i think somewher in connection or somewhere that. But if i m calling only that connection tht is working. wht is the problem???
Thanks
Ketan Khimani
NextGen InfoNET Pvt. Ltd.
[This message has been edited by Ketan Khimani (edited October 23, 2001).]
[This message has been edited by Ketan Khimani (edited October 24, 2001).]