V1_0.java [src/java/m/example/jdbc] Revision: f768e7ce2b40c43d54553d6cbe9a6810fcf36f24 Date: Tue Oct 15 12:16:47 MDT 2019
/*
* 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.SessionLogger;
import csip.annotations.*;
import csip.utils.Binaries;
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)
*/
/**
*
* @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 = getResourceJDBC(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);
}
}
@Override
protected void postProcess() throws Exception {
putResult("result", "done.");
}
}