bbs_title的数据项的数据类型?
或者你应该:
strSQL="insert into bbs_title(subject,username,message) values('?','?','?')";

解决方案 »

  1.   

    我用的是MS SQL7
    字段类型分别为:varchar,varchar,text.
    请大虾讲下数据类型要注意的问题
      

  2.   

    try
    {
    strSQL="insert into bbs_title(subject,username,message) values(?,?,?)";
    PreparedStatement prestmt=conn.prepareStatement(strSQL);
    prestmt.setString(1,subject);
    prestmt.setString(2,username);
    prestmt.setString(3,message);
    prestmt.executeUpdate();}
    catch(Exception de)
    {
    System.err.print("de.executeQuery:"+de.getMessage());
    }
      

  3.   

    我想是不是你没有提交(commit)的原因。
    最后调用一下conn的commit方法。
      

  4.   

    String sConnStr="jdbc:odbc:doctor";
    Connection conn=null;
    conn=DriverManager.getConnection(sConnStr,"doctor","doctor");以上都是正确的,我测试过
    try
    {
    //也可在这设置conn.setAutoCommit(true);
    strSQL="insert into bbs_title(subject,username,message) values(?,?,?)";
    PreparedStatement prestmt=conn.prepareStatement(strSQL);
    prestmt.setBytes(1,subject.getBytes("GBK"));
    prestmt.setBytes(2,username.getBytes("GBK"));
    prestmt.setBytes(3,message.getBytes("GBK"));
    prestmt.executeUpdate();
    //或者在这调用 conn.commit();
    }
    catch(Exception de)
    {
    System.err.print("de.executeQuery:"+de.getMessage());
    }
    祝你成功!
      

  5.   

    谢谢楼上的各位,不是在数据类型方面的问题。而是它根本不执行TRY的操作
    我用out.print(username0;语句测试,它执行的是catch
    catch(Exception de)
    {
    System.err.print("de.executeQuery:"+de.getMessage());
    out.print(username);测试语句
    }
      

  6.   

    用setString不可以吗?
    是不是用的jdbc:odbc版本不支持text类型
    在try中移动你的print语句,看错误出在何处把catch改成
    catch(Exception de)
    {
    System.err.print(de);
    }
    看错误提示是什么!
      

  7.   

    把catch改成
    catch(Exception de)
    {
    out.print(de);  //用out输出比较清楚
    }
    看错误提示是什么!
      

  8.   

       首先,你用de.getMessage();得到的异常信息并不够详细,而应该用de.printStackStrace(),这是一个好习惯,特别是你运行遇到出错时。然后,要充分利用抛出的异常信息,你在上面说了不少,但没有人知道你的错误信息到底什么,说得具体一点就是,你这里的出错信息到底是SQL引起的还是其它原因,并且从代码看,很可能是所谓的编码转换引起的,正如dynku(随风来去)所说,用setString()试试吧。
      

  9.   

       还有你在jsp中,要用out.print();而不是System.out.print();来捕捉异常
      

  10.   

    我改用out.print(de)输出的结果是:
    java.lang.NullPointerException 这是什么错误?
      

  11.   

    conn=DriverManager.getConnection(sConnStr,"doctor","doctor");
    PreparedStatement prestmt=conn.prepareStatement(strSQL);
    中conn、prestmt可能有一个是空指针。所以抛出例外
      

  12.   

    也有可能是3个参数中的一个值是NULL,这样也会出错,在前面加上一个判断,验证一下他们的值是否一定有.最好是逐行的检查,虽然笨点,但很有效。
      

  13.   

    其实作为jsp的编写,连接数据库部分最好是用bean,这样可以保证程序的清晰,也好判断错误的发生.所有的代码写在一起,很容易产生“交叉感染”,难以判断.