oracle 读取本地文件执行sql

package com.kingdee.eas.custom.comm;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import com.kingdee.bos.BOSException;

public class Mytest {
	
	
	
	public static void main(String[] args) throws BOSException, IOException {
		  // 读取SQL文件
        BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\12593\\Desktop\\导出的sql 无法执行.txt"));
        String line;
        StringBuilder sql = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            sql.append(line);
        }
        reader.close();
 
        
        // Oracle数据库连接参数
        String url = "jdbc:oracle:thin:@192.168.91.137:1521:myora";
        String username = "eas";
        String password = "kingdee";

        // 加载Oracle JDBC驱动程序
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e) {
            System.out.println("无法加载Oracle JDBC驱动程序");
            e.printStackTrace();
            return;
        }

        // 建立与Oracle数据库的连接
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url, username, password);
            System.out.println("成功连接到Oracle数据库");
            
            // 创建Statement对象
            Statement statement = connection.createStatement();
            try {
				statement.execute(sql.toString());
			} catch (Exception e) {
			   System.out.println("执行异常");
				e.printStackTrace();
			}
            // 关闭连接
            statement.close();
        } catch (SQLException e) {
            System.out.println("无法连接到Oracle数据库");
            e.printStackTrace();
        } finally {
            // 关闭数据库连接
            try {
                if (connection != null) {
                    connection.close();
                    System.out.println("关闭Oracle数据库连接");
                }
            } catch (SQLException e) {
                System.out.println("关闭Oracle数据库连接出错");
                e.printStackTrace();
            }
        }
    }
        
        
        
    
	
	

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值