Connection con = null;
ResultSet rs = null;
Statement smt = null;

try
{
     con = ConnectionManager.getConnection();
     con.setAutoCommit(false); // 禁止自动提交,设置回滚点// 将用户上行记录存入userinput表中String sql="insert into userinput from " + file + " with (fieldterminator=',',rowterminator='\n')";
                                    
smt.executeUpdate(sql);
con.close();con=null;
}
catch(Exception e)
{ try {if(smt!=null) smt.close();}catch(SQLException sqle){}
try {if(con!=null) con.close();}catch(SQLException sqle){}

}

解决方案 »

  1.   

    是不是在con.close()前应该提交一下?
      

  2.   

    smt.executeUpdate(sql);我已经在con.close()前提交了啊
      

  3.   

    是在con.close()前执行con.commit();
      

  4.   

    我在tomcat中打印出的错误提示为“java.lang.NullPointerException”
      

  5.   

    我把回滚去掉了,但是还是报错,在tomcat中打印出的错误提示为“java.lang.NullPointerException”
      

  6.   

    我没有断点测试的工具,都是直接写在程序里,然后打印出在tomcat中
      

  7.   

    String sql="insert into userinput from " + file + " with (fieldterminator=',',rowterminator='\n')";
    中的 file文件定义怎么样 ?
      

  8.   

    你用什么开发工具 ?
    eclipse.exe都有自带的断点插件
      

  9.   

    file是文本文件,每列之间用"逗号"间隔开,我没用eclipse,是用ultredit 来写的程序,所以没有断点插件,希望大家帮忙看看我的程序到底哪地方有问题,谢谢
      

  10.   

    try{
    con.setAutoCommit(false)
    执行sql语句
    然后要con.commit();
    }catch(SQLException e){
       con.rollback();
    }
      

  11.   

    现在代码更改为如下,但是运行的时候仍然会报错,file的路径为"D:\SN\1111.txt", 错误提示为"D:附近有语法错误",郁闷,大家再帮忙看看Connection con = null;
    ResultSet rs = null;
    Statement smt = null;try
    {
         con = ConnectionManager.getConnection();
         smt = con.createStatement();
         
    // 将用户上行记录存入userinput表中String sql="bulk insert  userinput from " + file + " with (fieldterminator=',',rowterminator='\n')";
                                        
    smt.executeUpdate(sql);
    smt.close();smt=null;
    con.close();con=null;
    }
    catch(Exception e)
    {try{if(smt!=null) smt.close();}catch(SQLException sqle){}
    try{if(con!=null) con.close();}catch(SQLException sqle){}}
      

  12.   

    搞定了,谢谢大家,这个代码是正确的了,这是将文本文件导入到数据库中,想问问大家可以将excel文件导入到数据库吗??Connection con = null;
    ResultSet rs = null;
    Statement smt = null;try
    {
         con = ConnectionManager.getConnection();
         smt = con.createStatement();
         
    // 将用户上行记录存入userinput表中String sql="bulk insert  userinput from '" + file + "' with (fieldterminator=',',rowterminator='\n')";
                                        
    smt.executeUpdate(sql);
    smt.close();smt=null;
    con.close();con=null;
    }
    catch(Exception e)
    {try{if(smt!=null) smt.close();}catch(SQLException sqle){}
    try{if(con!=null) con.close();}catch(SQLException sqle){}}