日期:2014-05-20  浏览次数:20846 次

简单数据库中更新数据出错 牛人们看下啊
Java code


package com.test.zhuce;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Cshi {

      
    public static void main(String[] args) throws ClassNotFoundException 
    {
         Connection con = null;
        Statement sql=null;
         ResultSet rs=null;
         String  uid="12092401";
         String  sid="2221";
            Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
            try {
                con=DriverManager.getConnection("jdbc:odbc:lib","","");
            } catch (SQLException e) {
                
                System.out.println("执行2");
            }
             String sqle="UPDATE yonghu set id1='"+sid+"' WHERE id="+"\'"+uid+"\'";
                try {
                    sql.executeUpdate(sqle);
                } catch (SQLException e)
                {
                    System.out.println("执行");
                }

    }

}



错误信息是:java.lang.NullPointerException

------解决方案--------------------
Statement sql=null;

sql= conn.createStament