首页 > 解决方案 > 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)?

谢谢兄弟。

标签: javapostgresql

解决方案


推荐阅读