高分请教java.sql.SQLException: The transaction is no longer active
调用的时候第一次没错,第2次报java.sql.SQLException: The transaction is no longer active - status: 'Committed'. No further JDBC access is allowed within this transaction.
我都要疯了,帮我看看吧
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import com.tyy.pub.DbCon;
import java.sql.Connection;
import javax.naming.Context;
import java.util.Hashtable;
public class LoginBean
implements SessionBean {
SessionContext sessionContext;
Connection con=null;
public void ejbCreate() throws CreateException {
/* try {
con = DbCon.getConnection();
}
catch (Exception ex) {
throw new CreateException(ex.getMessage());
}*/
try{
Hashtable hs=new Hashtable();
hs.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
hs.put(Context.PROVIDER_URL,"t3://localhost:7003");
Context ctx=new javax.naming.InitialContext(hs);
javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("hop");
con=ds.getConnection();
}catch(Exception ex){
ex.printStackTrace();
}
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public String CheckLog(String user, String pwd) throws Exception{
try{
String name=user.toUpperCase();
String p=pwd.toUpperCase();
java.sql.Statement st=con.createStatement();
java.sql.ResultSet rs=st.executeQuery("select name,password from employee where employ_no='"+name+"'");
if(rs.next()){
if(rs.getString("password").equals(p)){
return rs.getString("name");
}else{
return "1";//密码 错误
}
}
}catch(Exception e){
throw e;
}
finally{
try{
if(con!=null){
con.close();
}
}catch(Exception e){
}
} return "0";//用户名错误
}
}