回 帖 发 新 帖 刷新版面

主题:急!急!怎么用JSP将指定的TXT文件导入到ORACLE数据库中

下面是我自己的代码  高手们帮我看看有没有问题

<%@page import="java.util.Date,java.sql.*,com.mobile.operator.bean.*" contentType="text/html;charset=utf-8"%>
      <%
 try{                         
      Class.forName("oracle.jdbc.driver.OracleDriver");                         
      }         
      catch(ClassNotFoundException e1)                         
      {                         
      out.print("driver is not exist");                         
      }             
      try{                         
      Connection conn_txt=DriverManager.getConnection("jdbc:Driver={Microsoft Text Driver(*.txt;*.csv)}";DBQ="C:\test\mobile_numbers.txt");                         
      Statement stmt_txt=conn_txt.createStatement();                                                                                                         
      String str_txt="Select * From mobile_numbers";                         
      ResultSet rs_txt=stmt_txt.executeQuery(str_txt);                         
      while(rs_txt.next())                         
      {         
      mobile_Number=rs_txt.getString(1);         
      mobile_Typer=rs_txt.getString(2);
      card_Number=rs_txt.getString(3);
      is_Available=rs_txt.getString(4);         
            
      if(mobile_Number!=null&&!mobile_Number.trim().equals(""))         
      {         
               Connection conn=Conn.getConnection();         
                    String str_insert="insert into TMobiles(mobile_Number,mobile_Type,card_Number,is_Available)values(?,?,?,?)";         
                      PreparedStatement stmt=conn.prepareStatement(str_insert);         
                          stmt.setString(1,mobile_Number);         
                     stmt.setString(2,mobile_Typer);       
                 stmt.setString(3,card_Number);     
           stmt.setString(4,is_Available);       
           stmt.executeUpdate();         
      }         
                 }         
  }         
      catch(SQLException e)         
      {          e.printStackTrace();   
      }     
%>

回复列表 (共1个回复)

沙发

test yourself

我来回复

您尚未登录,请登录后再回复。点此登录或注册