V1_0.java [src/java/m/example/jdbc] Revision: 1572f2247372537df70090f135538920c9cc91ba Date: Mon Sep 12 14:29:39 MDT 2016
/*
* 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.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 oms3.annotations.*;
/*
@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)
*/
/**
*
* @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 {
@Override
protected void doProcess() throws Exception {
try (Connection c = getResourceJDBC("db"); 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);
}
}
@Override
protected void postProcess() throws Exception {
putResult("result", "done.");
}
}