sql = "insert into counter(date,today,first,second,third,forth,fifth,sixth) 
       values(' "   + time +   "  ','0','0','0','0','0','0','0') ";time为字符串,其值必须连接。而直接填time,则相当于字段date的值为time了

解决方案 »

  1.   

    我的counter表除了date是文本的数据类型,其它的都是整型
      

  2.   

    我觉得语句没错。
    不然你把这句SQL打印出来,直接在execel里运行看看有没有问题。
      

  3.   

    晕,乱说了,是access里面运行
      

  4.   

    access里在那个地方运行?
    还没用过
      

  5.   

    sql="insert into counter(date,today,first,second,third,forth,fifth,sixth) values('"+time+"',0,0,0,0,0,0,0)";你有很多字段都是关键字,很可能是这出的问题,都加上中括号改为
    sql="insert into [counter]([date],[today],[first],[second],[third],[forth],[fifth],[sixth]) values('"+time+"',0,0,0,0,0,0,0)";
    在看看
      

  6.   

    silverend(白银末裔) ( ) 不好意思,提醒一下,你的写法和楼主是一样的,都是一个字符串
    (楼主写了++了)建议楼主将后面的六个0取消,只插入第一个time试一下
      

  7.   

    access数据库权限的问题,打开数据库设置对every的权限试试
      

  8.   

    if(!rs.next())
    {
    sql="insert into counter(date,today,first,second,third,forth,fifth,sixth) values('"+time+"',0,0,0,0,0,0,0)";
    rs=smt.executeQuery(sql);
    }
    ...
    代码本身就有问题,不能用executeQuery()这个方法,用executeUpdate();
    你试试
      

  9.   

    不能用executeQuery()这个方法,应该是执行查询语句;
      

  10.   


    <%
    String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
    String URL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=h:/inetpub/wwwroot/test/data/total.mdb";
      Connection conn = null;
      try
      {
       Class.forName(DRIVER);
       conn = DriverManager.getConnection(URL);
      }
      catch(ClassNotFoundException ex)
      {
       out.println(ex);
      }
      catch(SQLException ex)
      {
       out.println(ex);
      }
         Statement smt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
        String sql;
        ResultSet rs;
    %>
    以上为文件:opendata.jsp<%@ page contentType="text/html;charset=gb2312" language="java" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.sql.*" %>
    <%@ include file="opendata.jsp" %>
    <%
    request.getSession(true);
    int month,day,hour,today,total,select;
    String time;
    String errmsg=request.getParameter("errmsg");
    GregorianCalendar calendar;
    calendar= new GregorianCalendar();
    month =calendar.get(Calendar.MONTH)+1;
    day=calendar.get(Calendar.DAY_OF_MONTH);
    hour=calendar.get(Calendar.HOUR_OF_DAY);
    time="m"+String.valueOf(month)+"d"+String.valueOf(day);
    sql="select * from counter where date='"+time+"'";
    rs =smt.executeQuery(sql);
    if(!rs.next())
    {
    sql = "insert into counter(date,today,first,second,third,fourth,fifth,sixth)+values('"+time+"',0,0,0,0,0,0,0)";
             try
    {
    smt.executeUpdate(sql);
    }catch(Exception ex){}
    }
    sql="select * from counter where today=12";
    rs=smt.executeQuery(sql);
    today=rs.getInt(1);
    select=(int)Math.floor(hour/4)+1;
    sql="slect * from total";
    rs=smt.executeQuery(sql);
    total=rs.getInt(1);
    if(session.isNew())
    {
    today++;
    switch(select)
    {
    case 1: sql="update counter set today="+today+",first=first+1 where date='"+time+"'";
           smt.execute(sql);
           break;
    case 2: sql="update counter set today="+today+",second=second+1 where date='"+time+"'";
           smt.execute(sql);
           break;
    case 3: sql="update counter set today="+today+",third=third+1 where date='"+time+"'";
           smt.execute(sql);
           break;
    case 4: sql="update counter set today="+today+",fourth=fourth+1 where date='"+time+"'";
           smt.execute(sql);
           break;
            case 5: sql="update counter set today="+today+",fifth=fifth+1 where date='"+time+"'";
           smt.execute(sql);
           break;
    case 6: sql="update counter set today="+today+",sixth=sixth+1 where date='"+time+"'";
           smt.execute(sql);
           break;
    }
    total++;
    sql="update total set total=total+1";
    smt.executeQuery(sql);
    smt.close();
    conn.close();
    }
    %>
    <html>
    <title>人数浏览统计</title>
    <p align=center><img src=zct.jpg><br>
    <%
    String showcount=String.valueOf(total);
    out.print("你是本站的第  ");
    for(int i=0;i<showcount.length();i++)
    out.print("<img src="+showcount.charAt(i)+".jpg>");
    out.print("  位上网使用者<br>");
    showcount=String.valueOf(today);
    out.print("您是今天的第  ");
    for(int i=0;i<showcount.length();i++)
    out.print("<img src="+showcount.charAt(i)+".jpg>");
    out.print(" 位上网使用者");
    %>
    <hr>
    <center>
    <form action=search.jsp method=post>
    <table border=0><tr>
       <td><font color=green>查询上网人数统计:</font></td>
       <td><select size=1 name=month>
           <option select>1<option>2<option>3<option>4<option>5<option>6
           <option>7<option>8<option>9<option>10<option>11<option>12</select>月</td>
       <td><select size=1 name=day>
           <option select>1<option>2<option>3<option>4<option>5<option>6
           <option>7<option>8<option>9<option>10<option>11<option>12<option>13<option>14<option>15<option>16
           <option>17<option>18<option>19<option>20<option>21<option>22<option>23<option>24<option>25
           <option>26<option>27<option>28<option>29<option>30<option>31</select>日</td>
      <td><input type=submit name=SEND value=查询></td>
    </tr>
    <tr>
      <td colspan=4 align=center>
      <a href=search.jsp?month=<%=month%>&day=<%=day%>>
       <font size=3>查看今日各时段流量统计</font></a></td>
    </tr>
    </table>
    </form>
    </html>
    运行后出现:
    java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
    at sun.jdbc.odbc.JdbcOdbc.SQLGetDataInteger(JdbcOdbc.java:3812)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getDataInteger(JdbcOdbcResultSet.java:5642)
    at sun.jdbc.odbc.JdbcOdbcResultSet.getInt(JdbcOdbcResultSet.java:585)
    at _test._counter._count__jsp._jspService(H:\Inetpub\wwwroot\test\counter\count.jsp:31)
    at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
    at com.caucho.jsp.Page.subservice(Page.java:506)
    at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
    at com.caucho.server.http.Invocation.service(Invocation.java:315)
    at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
    at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
    at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
    at java.lang.Thread.run(Thread.java:534)