我有一個ORACLE SQL sctipt,有幾個查詢和表,我想在程序開始時從我的java程序運行該腳本,以確保一切都在正確的位置。我找到了一個運行腳本的代碼,但由於某種原因它不起作用。任何人都可以提供樣品給我,以便我可以跟隨它。如何從java執行sql文件
這是我發現:
try {
String line;
Process p = Runtime.getRuntime().exec ("psql -U sas -d oracle -h @localhost -f Lab_05_Tables.sql");
BufferedReader input =new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
}
catch (Exception err) {
err.printStackTrace();
}
但它不工作,雖然。
錯誤
java.io.IOException: Cannot run program "psql": CreateProcess error=2, The system
cannot find the file specified
什麼不起作用?你有錯誤嗎? – talnicolas
格式化您的代碼,否則downvotes ... – Beginner
是不是'psql'的PostgreSQL命令行?它也可以處理Oracle嗎? – Thilo