当前位置: 代码迷 >> Java Web开发 >> 'try' without 'catch' or 'finally' 有关问题
  详细解决方案

'try' without 'catch' or 'finally' 有关问题

热度:357   发布时间:2016-04-17 15:38:42.0
'try' without 'catch' or 'finally' 问题
jsp文件:
<%@   page   language= "java "   import= "java.sql.* "%>
<%@   page   import= "java.util.* "%>
<%@   page   import= "java.text.* "%>
<%@   page   import= "usebean.* "   %>
<SCRIPT   language=javascript   type= " ">
function   backward()
{history.back();}
</SCRIPT>
<html>
<head>
<title> 登陆信息 </title>
</head>
<body   bgcolor= "#ffffff "   text= "#00000 ">
<jsp:useBean   id= "db "   scope= "page "   class= "usebean.opendb "/>
<%
    String   uid=request.getParameter( "uid ");
    String   pwd=request.getParameter( "pwd ");
    String   sql= "select   *   from   bbsUser   where   uid= ' "+uid+ " '   and   pwd= ' "+pwd+ " ' ";
    ResultSet   rs=db.executeQuery(sql);
    if(rs.next())
    {rs.close();
      java.util.Date   m_date=new   java.util.Date();
      DateFormat   df=DateFormat().getDateInstance();
      String   lastTime=df.format(m_date);
      sql= "update   bbsUser   set   logonTimes+1,lastTime= ' "+lastTime+ " '   where   uid= ' "+uid+ " ' ";
      rs=db.executeQuery(sql);
      session.setAttribute( "uid ",uid);
%>
<SCRIPT   language=javascript   type= " ">
self.location= "bball.jsp ";
</SCRIPT>
<%
    }
else
{rs.close();}
%>
<p> 对不起,你的输入有误! </p>
<p> <input   type=button   name= "button2 "   value= "返回上一步 "   onClick= "backward() "> </p>
<%
    }
%>
</body>
</html>
opendb.java   文件
package   usebean;
import   java.text.*;
import   java.sql.*;
public   class   opendb
{
    String   name;
String   password;
  String   url;
    Connection   con;
  PreparedStatement   ps;
    ResultSet   rs;
  public   opendb()
  {
    name= "boya ";
    password= "123 ";
    url= "jdbc:odbc:boya ";
    con=null;
    ps=null;
    rs=null;
  }
  public   ResultSet   executeQuery(String   sql)
  {
                try{

    Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
    con=DriverManager.getConnection(url,name,password);
    ps=con.prepareStatement(sql);
    rs=ps.executeQuery();
    if(con!=null)   con.close();
    }
    catch(Exception   e)
    {e.printStackTrace();}
    return   rs;
  }
  public   void   executeUpdate(String   sql)
  {
                try{