updateCount=Stmt.executeUpdate(sql);
执行SQL语句返回是整数吗?

解决方案 »

  1.   

    updateCount=Stmt.executeUpdate(sql);
    执行SQL语句返回是整数吗?
    可以说详细点吗?我是第一次做这种程序
    有些东西不太懂的呀,呵呵~是个菜鸟哦:)
      

  2.   

    怎么返回呀?
    是不是跟JAVA里面那样用RETURN 呀
    还是其他的方法?
      

  3.   

    在执行“updateCount=Stmt.executeUpdate(sql);“前检查一下sql是否正确,先把sql想办法显示出来,然后看执行结果,实在不行,检查一下connection是否为自动更新
      

  4.   

    executeUpdate
    public int executeUpdate(String sql)
                      throws SQLException
    Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. Parameters:
    sql - an SQL INSERT, UPDATE or DELETE statement or an SQL statement that returns nothing 
    Returns:
    either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing 
    Throws: 
    SQLException - if a database access error occurs or the given SQL statement produces a ResultSet object
      

  5.   

    Rst.next();
    这句干吗?
      

  6.   

    next
    public boolean next()
                 throws SQLException
    Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on. 
    If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read. 
    Returns:
    true if the new current row is valid; false if there are no more rows 
    Throws: 
    SQLException - if a database access error occurs
      

  7.   

    Rst.next();
    这句干吗?加上与注销掉都是一样的呀?
      

  8.   

    把你的sql打出来,然后复制,到数据库运行一下,看看对不对。
      

  9.   

    while(Rst.next())
       {
        //admin_id=Rst.getString("admin_id");
        admin_user=Rst.getString("admin_user");
        admin_power=Rst.getInt("admin_power");
       }
    你是只想取最后一条记录的信息吗?建议你使用if(Rst.next()) {}在执行新的sql前,
    rs.close()
    stmt.close()接下来再生成statement,最后执行并关闭。
      

  10.   

    update admin set admin_power=3 where admin_id=7
    这样子可以运行的呀
    而且可以更改数据库的呀
      

  11.   

    那你out.print(updateCount);一下,看看是多少?
      

  12.   

    out.print(updateCount);
    打印出来的的结果是0
      

  13.   

    try
    {
    stmt.executeUpdate(sql);
    int aa=0;
    aa=stmt.executeUpdate(sql);
    out.print(aa);----aa is 1;
    }
      

  14.   

    if(admin_power!=30)
        {
         admin_power=admin_power+1;      String sql="update admin set admin_power="+admin_power+" where admin_id="+admin_id+"";      Rst.next();
         //Stmt.executeUpdate(sql);
         ^^-----------------------------------这里被你注释掉了,sql将不被执行.
          //Conn.commit();
         int updateCount=0;
         updateCount=Stmt.executeUpdate(sql);//这里只是返回一个int型的值,并不执行sql
             if(updateCount>0)
             {
               out.print("有"+updateCount+"条记录更新成功");
             }
             else
             {
               out.print("更新失败");
             }          }      }
      

  15.   

    首先,你把程序中的sql语句拷贝到数据库中去执行,看一下有什么情况发生,如果数据库中的   updatecount也为0,那就不是程序的错误了;如果数据库中执行没有错误,那就说明你的程序中有错,这一点我也难以理解,照理说如果数据库访问出现错误,是会抛出SQLException异常的。
      

  16.   

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
    Connection con = DriverManager.getConnection("jdbc:odbc:"+dsnname+"",""+DBusername+"",""+DBpwd+""); 
    java.sql.Statement stmt = con.createStatement(); 
    ResultSet rs;你确定已经连上数据库了??
    我怎么没看见你的con?
      

  17.   

    我有个"date.jsp文件的
    我在上面用<%@ include file="data.jsp"%>
    调用的
    还有我可以把数据库里的东西掉出来但就是不能
    修改呀:)
      

  18.   

    sql在数据库里执行时完全正确的
      

  19.   

    你有没有试试在本页连接数据库,新建立一个Statement对象,然后再执行你的sql?
      

  20.   

    : acefr() 
    可以把你的QQ告诉我吗?
    我好更好的向你请教可以吗?
    或者邮箱也可以
      

  21.   

    <%@ page contentType="text/html; charset=GBK" %>
    <%@ page  import="java.sql.*" %><%
    java.sql.Connection Conn;
    java.sql.Statement Stmt;
    java.sql.ResultSet Rst;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Conn=DriverManager.getConnection("jdbc:odbc:soft2","lx","lx");
    Stmt=Conn.createStatement();String submit=request.getParameter("Submit");
    String admin_id=request.getParameter("admin_id");
    String admin_user="";
    int admin_power=0;if(submit!=null)
     {  if(submit.equals("提升"))
      {
        Rst=Stmt.executeQuery("select * from admin where admin_id="+admin_id+"");    if(Rst.next())
       {
        //admin_id=Rst.getString("admin_id");
        admin_user=Rst.getString("admin_user");
        admin_power=Rst.getInt("admin_power");
       }
        if(admin_power!=30)
        {
         admin_power=admin_power+1;
          String sql="update admin set admin_power="+admin_power+"where admin_id="+admin_id+"";
          Rst.next();
         Stmt.executeUpdate(sql);
          //Conn.commit();
         int updateCount=0;
         updateCount=Stmt.executeUpdate(sql);
         out.print(updateCount);
             if(updateCount>0)
             {
               out.print("有"+updateCount+"条记录更新成功");
             }
             else
             {
               out.print("更新失败");
             }    }
        //  return(sql);}
        /* else if(submit.equals("下降"))
          {
            Rst=Stmt.executeQuery("select * from admin where admin_id="+admin_id);
            while(Rst.next())
            {
              admin_user=Rst.getString("admin_user");
              admin_power=Rst.getInt("admin_power");
            }
            if(admin_power!=0)
            {
              admin_power=admin_power-1;
              String sql="update admin set admin_power=3 where admin_id=4";//+admin_id;
              Rst.next();
              Stmt.executeUpdate(sql);
            }
          }*/
          //Rst.close();
         //Stmt.close();
      //}
    }
    %>
    <html>
    <head>
    <title>
    用户管理
    </title>
    </head>
    <body bgcolor="FFFFFF" text="000000">
    <div align="center"><b><font color="#FF6600">会员信息管理</font></b>
     <table width="760" border="0" cellspacing="2" cellpadding="2" bgcolor="#000000">
      <tr bgcolor="FFFFFF">
        <td height="20" width="259">用户名</td>
        <td height="20" width="300">用户等级</td>
        <td height="20" width="181">等级提降</td>
       </tr>
    <%
     // int admin_id=0;
     // String admin_user="";
     // int admin_power=0;
      int I;
    //int mum=0;
    //int p_id=request.getParameter("admin_id");
    //ResultSet Rs=soft.executeQuery("select max(admin_power) as maxorderpower,min(admin_pwoer) as minorderpower from admin where admin_id="+p_id+"");
    Rst=Stmt.executeQuery("select max(admin_power) as maxorderpower,min(admin_power) as minorderpower  from admin");Rst.next();
    int maxorderpower=Rst.getInt("maxorderpower");
    int minorderpower=Rst.getInt("minorderpower");
    //ResultSet Rs=soft.executeQuery("select * from admin order by admin_power desc");
    Rst=Stmt.executeQuery("select * from admin order by admin_power desc");
    while(Rst.next())
    {
       //admin_id=Rs.getInt("admin_id");
       admin_user=Rst.getString("admin_user");
       admin_power=Rst.getInt("admin_power");
       // mum=Rs.getInt("admin_id");
    %>
    <tr>
        <td width="259" bgcolor="#F3F3F3"><%=admin_user%></td>
        <td width="300" bgcolor="#F3F3F3"><%=admin_power%></td>
        <td width="181" bgcolor="#F3F3F3">
    <form name="form1" method="post" action="">
       <input type="hidden" name="h_power" value="<%=admin_power%>">
       <%if(admin_power!=maxorderpower)%>
        <input type="submit" name="Submit" value="提升">
      <%if(admin_power!=minorderpower)%>
         <input type="submit" name="Submit"value="下降">
    </form>
      </td>
      </tr>
    <%
    }
    %>
    </table>
     </div>
    </body>
    </html>
    代码都在这里了呀:)
    麻烦帮我看看;)