Reputation: 7200
I'm using PostgreSQL in Java and I want to create a database structure.
How I can run a SQL script using psql?
Upvotes: 0
Views: 183
Reputation: 7200
I found this code that works like psql:
public void ejecutarScript(String file) throws IOException, SQLException {
Statement st3 = conexion.createStatement();
BufferedReader in = new BufferedReader(new FileReader(file));
String str;
StringBuffer sb = new StringBuffer();
while ((str = in.readLine()) != null) {
sb.append(str + "\n ");
}
in.close();
st3.executeUpdate(sb.toString());
}
Upvotes: 1