V1_0.java [src/java/m/example/jdbc] Revision: default Date:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package m.example.jdbc;
import csip.ModelDataService;
import csip.api.server.ServiceException;
import csip.annotations.*;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import javax.ws.rs.Path;
import static m.example.jdbc.PoolClass.P_ID;
/*
@Resource(file = "${connect.url}", env = {"maxWait=10000",
"jmxEnabled=false"}, id = "patch", type = JDBC)
@Resource(file = "jdbc:postgresql://localhost/od?user=od&password=od",
env = {"maxWait=10000", "jmxEnabled=false"}, id = "db", type = JDBC)
*/
/**
* added docs
*
* @author od
*/
@Name("jdbc")
@Description("jdbc example")
@Path("m/jdbc/1.0")
@Polling(first = 2000, next = 2000)
@Resource(from = PoolClass.class)
public class V1_0 extends ModelDataService {
// private void ttt(Class<?> c, SessionLogger l) throws ServiceException {
// Connection cc = Binaries.getResourceJDBC(c, "test", l);
// }
@Override
protected void doProcess() throws Exception {
try (Connection c = resources().getJDBC(P_ID); Statement st = c.createStatement()) {
try (ResultSet rs = st.executeQuery("select * from patches;")) {
while (rs.next()) {
System.out.println(rs.getDouble("nval"));
}
}
} catch (SQLException | ServiceException ex) {
LOG.log(Level.SEVERE, null, ex);
}
}
// new fixed code
@Override
protected void postProcess() throws Exception {
results().put("result", "done.");
}
}