错误多多,吃饭回来再回答。1 hour

解决方案 »

  1.   

    把每个方法中的stmt = null;rs = null;什么的都取掉
      

  2.   


                    try
                    {
                        confirm.confirm() ;
                        ResultSet rs=confirm.executeQuery(aaa);
                    
                      
                    }catch(Exception e){
                            System.err.println(e.toString());
                    }
     没有输出,你自己写
      

  3.   

    hehe
    论坛里很多相关知识的
      

  4.   

    对表进行添加操作,我劝你还是用 stmt.executeUpdate(sql),而且添加操作也并不需要返回结果集啊
      

  5.   

    confirm.confirm() ;
         ResultSet rs=confirm.executeQuery(aaa);
    的方法好像还是不行啊?
      

  6.   

    对于一段数据库操作来说,应该这样:Connection conn = null;
    Statement  stmt = null;
    ResultSet  rs   = null;try
    {
        Class.forName(sDBDriver);
        conn = DriverManager.getConnection(sConnStr);
        stmt = conn.createStatement();    rs = stmt.executeQuery(sql);
    }
    catch ( Exception e )
    {
        e.printStackTrace();
    }
    finally
    {
        if ( rs != null ) rs.close();
        if ( stmt != null ) stmt.close();
        if ( conn != null ) conn.close();
    }
      

  7.   

    嗯,看到你的jsp代码中,想要使用ResultSet对象,这样不好。如果真要查看所有值,一般是将这些值填充到元素为Map对象的List对象中,executeQuery方法封装如下:public List executeQuery(String sql)
    {
    List list = new ArrayList();

    Connection conn = null;
    Statement  stmt = null;
    ResultSet  rs   = null;

    try
    {
        Class.forName(sDBDriver);
        conn = DriverManager.getConnection(sConnStr);
        stmt = conn.createStatement();

        rs = stmt.executeQuery(sql);

        ResultSetMetaData rsmd = rs.getMetaData();
        
        while ( rs.next() )
        {
         Map map = new HashMap();
        
         for ( int i = 0; i < rsmd.getColumnCount(); i++ )
         {
         map.put(rsmd.getColumnName(i), rs.getString(i));
         }
        
         List.add(map);
        }
    }
    catch ( Exception e )
    {
        e.printStackTrace();
    }
    finally
    {
        if ( rs != null ) rs.close();
        if ( stmt != null ) stmt.close();
        if ( conn != null ) conn.close();
    }

    return list;
    }
      

  8.   

    加载的数据库驱动程序和URL不一致。
      

  9.   

    使用:<%@ page import="firm.*" %>
    <%
        List list = confirm.executeQuery("insert into student values('eeewwq','wwwddd',77)");    for ( int i = 0; i < list.size(); i++ )
        {
            Map map = (Map)list.get(i);
            
            // 按列名        
            out.println(map.get("name"));
            out.println(map.get("age"));
        }
    %>
      

  10.   

    加载的数据库驱动程序和URL哪里不一致?
    谁看出来了?
      

  11.   

    呵呵,它加载sql server的JDBC驱动程序,却用JDBC-ODBC桥的连接字符串,挂羊头,卖狗肉!!
      

  12.   

    #MSQL
    com.microsoft.jdbc.sqlserver.SQLServerDriver
    jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=shark;SelectMethod=cursor
      

  13.   

    获得数据库连接那段,最好是用连接池,这样避免把连接字符串和driver字符串写在java里。可以用tomcat的,也可以自己做,呵呵。对于bean的使用,你理解不对。首先bean类通常是用来做数据库表格的映射。
    在jsp页面上,bean类和html代码中form标记内同名的可提交对象映射。1.比如对于一个数据库表student,它有三个字段id, name, age2.那么bean类这样写,其中每个属性都要有相应的get, set方法,而且把insert, update, delete, select方法也加进去,sql语句都在里面,只针对一个记录的操作:
    public class student
    {
        private String id = "";
        private String name = "";
        private String age = "";    public void setId(String id)
        {
            this.id = id;
        }
        public String getId()
        {
            return id;
        }
        
        public void setName(String name)
        {
            this.name = name;
        }
        public String getName()
        {
            return name;
        }
        
        public void setAge(String age)
        {
            this.age = age;
        }
        public String getAge()
        {
            return age;
        }
        
        public int insert()
        {
        }
        
        public int update()
        {
        }
        
        public int delete()
        {
        }
        
        public int select()
        {
        }
    }3.jsp程序:
    <%@ page contentType="text/html; charset=gb2312" %>
    <jsp:useBean id="cfm" class="firm.confirm" scope="request">
    <jsp:setProperty name="cfm" property="*"/>
    </jsp:useBean>
    <%
       // insert, update, delete, select 看条件了
       cfm.select();
    %>
    <html>
    <head>
    <meta content="text/html; charset=gb2312" http-equiv=Content-Type>
    </head>
    <body>
    <form method=post>
    <input type=text name=id value="<%=cfm.id%>">
    <input type=text name=name value="<%=cfm.name%>">
    <input type=text name=age value="<%=cfm.age%>">
    <input type=submit>
    </form>
    </body>
    </html>累死,玩cs去。
      

  14.   

    ResultSet rs=confirm.executeQuery(aaa);
    这句话明显有问题,插入操作返回的是一个整数,不是ResultSet,
    所以这里应该直接写一句 executeUpdate(aaa);
    ling:executeUpdate也要改写:
    public void executeUpdate(String sql){
        stmt = null;
        //rs = null;
        try{
          conn = DriverManager.getConnection(sConnStr);
          stmt = conn.createStatement();
          stmt.executeUpdate(sql);
          stmt.close();
          conn.close();
        }catch(SQLException ex){
          System.err.println("aq.executeQuery:" + ex.getMessage());
        }
        }
      

  15.   

    代码没有问题但
    stmt.close();
    conn.close();
    用的太早。
    建议用专门的方法关闭。\还有一个Statement只能打开一个ResultSet.