在存储过程中还是JAVA中
可以try catch捕获错误

解决方案 »

  1.   

    这就要看你在catch里要捕获什么错误了
      

  2.   

    可以捕获错误,也可以通过JSP把刚插入的数据取出来输出一下是否正确
      

  3.   

    还可以直接在你操作的数据库中
    直接用sql语句查相应的表的内容就知道是否成功了
      

  4.   

    一般返回SQLException 或者是你自己定义的记录已经存在的异常
    在jsp中捕捉到异常,给用户提示就行了.
      

  5.   

    Statement Interface的executeUpdate() method会返回一个整数,如果是大于0表示操作成功,等于0表示没有满足条件的记录,如果抛出异常表示操作失败
      

  6.   

    可以用JS做一个对话框啊,如果成功了就提示操作成功,如果错误就提示错误原因啊。比如说遇到SQLException就提示"SQL异常!",遇到ClassNotFoundException 就提示"找不到类",这样不就很友好吗!
      

  7.   

    最简单的方法是在数据库操作的bean里面定义一个String 用来返回结果:
    这是我的bean的写法。
    只要在页面调用getException()就可以知道操作是否成功,我觉得这种做法是代价比较小的了。哈哈,欢迎大家交流
    package sqlBean;import java.sql .*;
    import java.io.*;
    public class sqlBean {
    private String strip="";//"192.168.1.165";
    private String strport;
    private String strodbc;
    private String struser="";//"sa";
    private String strpassword="" ;
    private String temp;
    private int i;
    private String exception="操作成功!";String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String sConnStr = "";//"jdbc:odbc:biserver";
    //getfile gf = new getfile();
    //String sConnStr="";
    Connection connect = null;
    ResultSet rs = null;
    public void forName(){
    try {
      getfile();
      sConnStr="jdbc:odbc:"+strodbc;
    Class.forName(sDBDriver);
    }
    catch(java.lang.ClassNotFoundException e) {
      exception=e.getMessage();
    System.err.println( exception);
    }
    }
    public ResultSet executeQuery(String sql) {
    rs = null;
    try {
      forName();
      if(connect==null)
      connect = DriverManager.getConnection(sConnStr,"sa","");
      strpassword=strpassword.trim();
      if (strpassword.equals(""))
       {
        connect = DriverManager.getConnection(sConnStr,struser,"");
        }
    else
       {
         connect = DriverManager.getConnection(sConnStr,struser,strpassword);
       }
    Statement stmt = connect.createStatement(rs.TYPE_SCROLL_SENSITIVE,rs.CONCUR_READ_ONLY);
    rs = stmt.executeQuery(sql);
    }
    catch(SQLException ex) {
       exception=ex.getMessage();
    System.err.println(exception);
    }
     return rs;
    }
    public void updatesql(String sql) {
    try {
      forName();
    strpassword=strpassword.trim();
    if (strpassword.equals(""))
       {
        if(connect==null)
        connect = DriverManager.getConnection(sConnStr,struser,"");
        }
    else
       {
        if(connect==null)
        connect = DriverManager.getConnection(sConnStr,struser,strpassword);
        }
    Statement stmt = connect.createStatement();
    stmt.executeUpdate(sql);
    }
    catch(SQLException ex) {
       exception=ex.getMessage();
    System.err.println(exception);
    }
    }
    public String getException(){return exception;}