java - Psql 命令运行脚本插入 PostgreSQL
问题描述
我有脚本student.sql
,我想通过 Java 将此脚本运行到数据库。
我使用如下
final Process process = Runtime.getRuntime().exec("psql -d test3 -h 127.0.0.1 -p 5432 -U postgres -f student.sql", new String[]{"PGPASSWORD","root"});
if (process.waitFor() == 0) {
System.out.println("Success!");
} else {
System.out.println("error");
}
没有错误,也没有回应process.waitFor()
我的问题。
如何运行导入文件到数据库(postgres)?
谢谢兄弟。
解决方案
推荐阅读
- javascript - 如何在 react-modal 中设置组件?
- java - 为什么它无法读取bmp文件。?
- java - if else 选择 login.activity 或 register.activity 有问题
- pandas - 将 kdb 表保存到数据框,然后将数据框保存到 csv。错误地输出到 csv 的 null 和字符串值?
- javascript - 第一次触摸无法在应用中滚动
- javascript - 通过推送通知打开应用程序时未注册后退按钮处理程序
- openssl - 如何在不依赖 vcruntime-dll (/MT) 的情况下为 VC-WIN32 构建 openssl 1.1.1 dll
- entity-framework - 在保存上下文之前,Entity Framework Core 如何处理实例?
- shell - 如何从大文件中获取最小前缀
- swift - 如何从 Sqlite swift 中删除表视图行?