use of com.icodici.db.PooledDb in project universa by UniversaBlockchain.
the class PostgresLedger method addNode.
@Override
public void addNode(NodeInfo nodeInfo) {
try (PooledDb db = dbPool.db()) {
String sqlText = "insert into config(http_client_port,http_server_port,udp_server_port, node_number, node_name, public_host,host,public_key) values(?,?,?,?,?,?,?,?);";
try (PreparedStatement statement = db.statementReturningKeys(sqlText)) {
statement.setInt(1, nodeInfo.getClientAddress().getPort());
statement.setInt(2, nodeInfo.getServerAddress().getPort());
statement.setInt(3, nodeInfo.getNodeAddress().getPort());
statement.setInt(4, nodeInfo.getNumber());
statement.setString(5, nodeInfo.getName());
statement.setString(6, nodeInfo.getPublicHost());
statement.setString(7, nodeInfo.getClientAddress().getHostName());
statement.setBytes(8, nodeInfo.getPublicKey().pack());
db.updateWithStatement(statement);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
} catch (SQLException se) {
se.printStackTrace();
throw new Failure("add node failed:" + se);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations