import java.io.*; import java.sql.*;
public class ImportToOracle { public static void main(String[] args) { String database_name; String dataset; String dataset_description; String dataset_experiment_type; String dataset_maximum_probes; String dataset_organism; String dataset_title; String dataset_update_date; String dataset_value_type; String sDriver = "oracle.jdbc.driver.OracleDriver"; String sURL = "jdbc:oracle:thin:@211.69.192.178:1521:bio"; String sUsername = "geo"; String sPassword = "huangjing"; try { BufferedReader in = new BufferedReader(new FileReader("C:\\java\\Table\\Data.txt")); Class.forName(sDriver);//connect to database Connection conn = DriverManager.getConnection ( sURL, sUsername, sPassword ); System.out.println("connection succeed"); String sql = "insert into Dataset values(?,?,?,?,?,?,?,?,?)"; PreparedStatement pstmt = conn.prepareStatement(sql); database_name = in.readLine(); dataset = in.readLine(); dataset_description = in.readLine(); dataset_experiment_type = in.readLine(); dataset_maximum_probes = in.readLine(); dataset_organism = in.readLine(); dataset_title = in.readLine(); dataset_update_date = in.readLine(); dataset_value_type = in.readLine(); in.readLine(); while(database_name != null) { pstmt.setString(1,database_name); pstmt.setString(2,dataset); pstmt.setString(3,dataset_description); pstmt.setString(4,dataset_experiment_type); pstmt.setString(5,dataset_maximum_probes); pstmt.setString(6,dataset_organism); pstmt.setString(7,dataset_title); pstmt.setString(8,dataset_update_date); pstmt.setString(9,dataset_value_type); database_name = in.readLine(); dataset = in.readLine(); dataset_description = in.readLine(); dataset_experiment_type = in.readLine(); dataset_maximum_probes = in.readLine(); dataset_organism = in.readLine(); dataset_title = in.readLine(); dataset_update_date = in.readLine(); dataset_value_type = in.readLine(); in.readLine(); } conn.close(); in.close(); } catch(SQLException ex) { while(ex!=null) { ex.printStackTrace(); ex=ex.getNextException(); } } catch(IOException ex) { ex.printStackTrace(); } } } 编译说unreported exception java.lang.ClassNotFoundException;must be caught or declared to be thrown Class.forName(sDriver);//connect to database 哪位大虾指点一下
----------------解决方案--------------------------------------------------------
没人回阿
----------------解决方案--------------------------------------------------------
Class.forName()这个方法要抛出异常。需要用try...catch捕获。这个很常见的错误希望你记住,下次不要问这样的问题了,呵呵
----------------解决方案--------------------------------------------------------
我的Class.forName()是在try{}里面啊
----------------解决方案--------------------------------------------------------
我是向远程的oracle数据库导入数据,驱动程序路径应该怎么设置,或者应该把驱动程序拷到那个目录下
----------------解决方案--------------------------------------------------------
你好!adminyefei! import java.io.*; import java.sql.*; import oracle.jdbc.*; //这一句一定要加!
public class ImportToOracle { public static void main(String[] args) {
try { String sURL = "jdbc:oracle:thin:@127.0.0.1:1521:master "; String sUsername = "scott"; String sPassword = "jacky"; BufferedReader in = new BufferedReader(new FileReader("C:\\BOOTLOG.txt")); //盘符中的文件要存在。 Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); //这一句一定要加! DriverManager.registerDriver( new oracle.jdbc.OracleDriver()); //这一句一定要加! Connection conn = DriverManager.getConnection ( sURL, sUsername, sPassword ); System.out.println("connection succeed"); }catch(Exception e) { } } //你下面的我没看。 }
----------------解决方案--------------------------------------------------------