我得到Java.sql.Connection關閉每當我在我的生產服務器上上載我的應用程序時出現異常。生產服務器是Jboss。 我也嘗試過在QA,DEV服務器上不發生此問題。 我們是一個Web應用程序,每當我們遍歷特定的選項卡時,都會發生此異常。Java.sql連接關閉特定服務器上的異常
這是跟蹤:
2011-11-11 14:32:12983 ERROR [STDERR] java.sql.SQLException中:關閉連接 2011-11-11 14:32:12984 ERROR [ STDERR] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) 2011-11-11 14:32:12,984 ERROR [STDERR] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146 ) 2011-11-11 14:32:12,984 ERROR [STDERR] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) 2011-11-11 14:32:12,984錯誤[STDERR] at oracle .jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java :897) 2011-11-11 14:32:12,984 ERROR [STDERR] at oracle.jdbc.driver.PhysicalConnection.prepareStatement(PhysicalConnection.java:816) 2011-11-11 14:32:12,984錯誤[STDERR] at com.amadeus.mis.usermanagement.MisDb.prepareStatement(MisDb.java:72) 2011-11-11 14:32:12,984錯誤[STDERR] at com.amadeus.mis.usermanagement.MisDb.getCompId(MisDb.java :1002) 2011-11-11 14:32:12,984錯誤[STDERR] at com.amadeus.mis.usermanagement.MisDb.loadUnLinkedUsers(MisDb.java:1033) 2011-11-11 14:32:12,984錯誤[ STDERR] at org.apache.jsp.LinkUser_jsp._jspService(LinkUser_jsp.java:445) 2011-11-11 14:32:12,985 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java :70) 2011-11-11 14:32:12,985錯誤[STDERR]在javax.servlet.http.HttpServlet.service(HttpServlet.java:7 17) 2011-11-11 14:32:12,985 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387) 2011-11-11 14:32:12,985錯誤[STDERR ]在org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) 2011-11-11 14:32:12,985錯誤[STDERR]在org.apache.jasper.servlet.JspServlet.service(JspServlet。的java:266) 2011-11-11 14:32:12985 ERROR [STDERR]在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
我還附加一個代碼示例,這是發生錯誤的代碼。
public List<String>loadLinkedUsers(String uname)
throws Exception
{
List<String> userList = new ArrayList<String>();
String[]temp=uname.split("_");
String myschema=temp[0]+"_"+temp[1];
if(!getUserType(uname).equalsIgnoreCase("RC"))
{
PreparedStatement stmt = null;
stmt = prepareStatement("select res_user_id from"+" "+myschema+".res_user where login_id = ? and res_user_id !='Administrator'");
stmt.setString(1,uname);
try {
ResultSet rs = stmt.executeQuery();
while(rs.next())
{
userList.add(rs.getString(1));
}
rs.close();
} catch (Exception e) {
System.out.println("Exception"+e.getMessage());
}
stmt.close();
}
return userList;
}
public int getCompId(String userName)
{
PreparedStatement stmt;
int temp=0;
try{
stmt = prepareStatement("Select comp_id from mis.users where login_id = ?");
stmt.setString(1,userName);
ResultSet rs=stmt.executeQuery();
while(rs.next())
{
temp=rs.getInt(1);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return temp;
}
/**
* Load the information about users that are not Linked to
* the user who is logged in.
* (login_id, user_email, user_type_id from table mis.users)
* @param login
* @param users Vector that is filled with user information of type User.
* The previous data is not cleared.
* @throws SQLException
*/
public List<String> loadUnLinkedUsers(String uname)
throws Exception
{
List<String>userList = new ArrayList<String>();
String[]temp=uname.split("_");
String myschema=temp[0]+"_"+temp[1];
int comp_id=getCompId(uname);
if(!getUserType(uname).equalsIgnoreCase("RC"))
{
PreparedStatement stmt1=null;
String query1="select res_user_id from"+" "+myschema+".res_user where login_id=? and res_user_id='Administrator'";
stmt1 = prepareStatement(query1);
stmt1.setString(1,uname);
try {
ResultSet rs1 = stmt1.executeQuery();
/*if(!rs1.next())
{
userList.add("Administrator");
}*/
} catch (Exception e) {
System.out.println("Exception"+e.getMessage());
}
PreparedStatement stmt = null;
String query="SELECT u.login_id FROM mis.users u LEFT JOIN mis.user_type t ON u.user_type_id = t.user_type_id WHERE comp_id = ? minus select res_user_id from"+" "+myschema+".res_user where login_id =?";
stmt = prepareStatement(query);
stmt.setInt(1,comp_id);
stmt.setString(2,uname);
try {
ResultSet rs = stmt.executeQuery();
while(rs.next())
{
userList.add(rs.getString(1));
}
rs.close();
} catch (Exception e) {
System.out.println("Exception"+e.getMessage());
}
stmt.close();
}
return userList;
}
請注意,這是用於創建Prepared Statements的函數。
protected Connection m_Connection;
/**
* Prepare a statement from the current connection
* @param strSql
* @return Prepared statement
* @throws SQLException
*/
protected PreparedStatement prepareStatement(String strSql) throws SQLException
{
logger.debug("SQL= " + strSql);
return m_Connection.prepareStatement(strSql);
}
那麼它缺少一些上下文,你的堆棧跟蹤從哪裏來。可能是連接超時太短。您可以延長它,或者試着修復即時關閉的連接。如果你需要幫助,那麼需要更多的代碼。 – Jerome
它也可能是嘗試使用已關閉的連接。 –