写:
try{
.........
}
catch(SQLException e)
{
out.print(e);
}

解决方案 »

  1.   

    http://www.csdn.net/Develop/read_article.asp?id=14033
      

  2.   

    http://www.csdn.net/Develop/read_article.asp?id=14033
      

  3.   

    在你的test类中可以这样:
    public void  sqlUpdate(String sStrSql) throws SQLException {
    }将try {test.sqlUpdate("......")} catch (e){......}可以改成这样:
    try {
    test.sqlUpdate("......") ;
    }catch(SQLException se) {
               se.printStackTrace(System.err);
        }以上是没有加事务处理的。你可加上。
      

  4.   

    看了weidegong兄的文章,受益良多
     Andrawu写的我看了,但不是很明白,sorry,学java时间太短,不知道你这样写与我的有什么主要差别?特别是printStackTrace(System.err)是什么意思?谢谢
    以下是我原来写的
    public void sqlUpdate(String sql)
    {
    try
    {
    Conn=DriverManager.getConnection(url,user,password);
    Statement Stmt=Conn.createStatement();
    Stmt.executeUpdate(sql);
    }
    catch (SQLException e)
    {
    System.err.println("Sql.executeUpdate : "+e.getMessage());
    }
    }
      

  5.   

    printStackTrace(System.err)
    以标准错误的形式输出一个错误和错误的堆栈
      

  6.   

    try:在test类中用throws不用try/catch。
    public void  sqlUpdate(String sql) throws SQLException {
    Conn=DriverManager.getConnection(url,user,password);
    Statement Stmt=Conn.createStatement();
    Stmt.executeUpdate(sql);
    }在外面调用用try/catch不用throws:
    private void doUpdate(){
    try {
    test.sqlUpdate("......") ;
    }catch(SQLException se) {
               se.printStackTrace(System.err);
        }
    }