你是不是实例化了一个抽象的方法,在main方法里面。

解决方案 »

  1.   

    就是连接数据的方法呀,代码如下,package java_jin;
    import java.sql.*;
    public class BatchUpdate
     {
    public static void main(String args[]) throws SQLException
    {
     ResultSet rs=null;
     PreparedStatement ps=null;
     String url="jdbc:oracle:thin:@195.100.130.55:1521:ora";
     Connection con;
     Statement stmt;
     //加载数据库驱动
     try{
         Class.forName("oracle.jdbc.driver.OracleDriver");
         }catch(java.lang.ClassNotFoundException e)
        {
        System.err.print("ClassNotFound Exception:");
        System.err.println(e.getMessage());
        }
     try{
       con=DriverManager.getConnection(url,"hr","hr");
       //提交连接请求
       con.setAutoCommit(false);
       stmt=con.createStatement();
       stmt.addBatch("insert into table_1 values(1,'新概念1')");
       stmt.addBatch("insert into table_1 values(2,'新概念2')");
       stmt.addBatch("insert into table_1 values(3,'新概念3')");
       int[]  updateCounts=stmt.executeBatch();
       con.commit();
       con.setAutoCommit(true);
       ResultSet uprs=stmt.executeQuery("select * from table_1");
       while(uprs.next())
        {
          int id=uprs.getInt("id");
          String xx=uprs.getString("name");
          System.out.println(id +" "+ xx);
               }
          uprs.close();
          stmt.close();
          con.close();
      }
      catch(BatchUpdateException b)
      {
      System.err.println("--BatchUpdateException---");
      System.err.println("SQLState:"+b.getSQLState());
      System.err.println("Message:"+b.getMessage());
      System.err.println("Vendor:"+b.getErrorCode());
      System.err.println("Update Counts:");
      int[] updateCounts=b.getUpdateCounts();
      for(int i=0;i<updateCounts[i];i++)
      {
      System.err.print(updateCounts[i]+" ");
      }
      System.err.println(" ");
      }
      catch(SQLException ex)
      {
      System.err.println("--SQLException---");
      System.err.println("SQLState:"+ex.getSQLState());
      System.err.println("Message:"+ex.getMessage());
      System.err.println("Vendor:"+ex.getErrorCode());
      }
     }
    }