没有出错信息,一切正常,我也很奇怪,但是就是写不进表中,但是我用“查询分析器”把命令打进去是可以执行的(写入),这说明我的“sql”语句是对的。真的很奇怪!

解决方案 »

  1.   

    我可真是个菜鸟哟,不敢说解答,学JAVA才一个月,之前有一年都没碰过任何语言,面向对象也是学JAVA才学的,还有,你写的程序太长,我也看不懂……只是胡乱猜测一番,你看是不是因为这:(我可不太识这些字,大概意思是默认的ResultSet 对象是不可更新的、仅向前游标的玩意,当然,你可更改属性……自己看样例吧,我说不好。。对了,管用的话要谢我哟,嘻嘻)
    A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable. The following code fragment, in which con is a valid Connection object, illustrates how to make a result set that is scrollable and insensitive to updates by others, and that is updatable. See ResultSet fields for other options. 
           Statement stmt = con.createStatement(
                                          ResultSet.TYPE_SCROLL_INSENSITIVE,
                                          ResultSet.CONCUR_UPDATABLE);
           ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
           // rs will be scrollable, will not show changes made by others,
           // and will be updatable
      

  2.   

    为森么不用mysql提供的jdbc驱动程序?
    看样子是你的url有问题!
      

  3.   

    我的jdbc驱动程序是对的,我在别的程序中也用db这个类,是可以的。
      

  4.   

    我现在发现一个新问题,就是我用‘查询分析器’再次写入数据库后,发现自动编号的一列跳了几个,这说明,我的java程序是往数据库中写数据(但是没有写成功),触发了自动编号这一列自动增加。 但是为什么没有成功的写入数据呢? 留言板表(bbs)
    ------------------------------------------------------------------
    字段名称            数据类型 NULL 描述
    -----------------------------------------------------------------
    留言id
    iBbsID                 int No PK
    自动生成,每次+1
    ------------------------------------------------------------------
    主题 
    nvTitle           Nvarchar(90) Yes 为主贴而设,回复贴   没内容
    ------------------------------------------------------------------
    作者
    ncAuthor           Nchar(9)         No References Key
    引用UserInfo.ncUserID
    ----------------------------------------------------------------
    回复数
    iReply           Int        Yes Default(0)
    ---------------------------------------------------------------
    发表时间
    dtTime         datatime         No 系统函数Getdate()
    ------------------------------------------------------------
    留言内容
    nvData         Nvarchar(1000) No
    --------------------------------------------------------------
    留言性质
    ncProp            Nchar(1) no     主贴是“1”,回复贴“0”
    -------------------------------------------------------------------
    回复留言id
    iReID              Int        yes Null表示没有回复(对主贴而言)靠此连接留言与回复留言
    -------------------------------------------------------------------
    点击数
    iClick             Int        yes Default(0)
      

  5.   

    问题在:rs=stmt.executeQuery(sql);executeQuery(sql)--此方法用于返回数据集rs的操作,即对应于"sql = select ..."的语句操作;
    对于数据库的insert、update、delete操作,应该用executeUpdate(sql);故,你需要在db.java中添加一方法,用于插入、删除、更新操作:
    public void executeUpdate(String sql)
    {
    try
    {
    conn=DriverManager.getConnection(sConnStr);
    Statement stmt=conn.createStatement();
    stmt.executeQuery(sql);
    }catch(SQLException sqle)
    {
    System.err.println("Error connectiong: "+sql);
    }
    }  
      

  6.   

    to salmon (salmon) :
      试了没??搞定了就结账!还有疑问就继续提问,不要让问题悬而不决!!希望大家一起养成良好的论坛习惯!
      

  7.   

    对,同意。
    我觉得可以试试cleverfish(一只鱼) 说的executeUpdate()
    可能问题就在这。
      

  8.   

    插入和修改数据要用  executeUpdate()方法