V1_0.java [src/java/m/example/jdbc] Revision: cd599a9513e088ae77a384f17f2298209b989cd3  Date: Sat Apr 25 07:52:02 MDT 2020
/*
 * 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 = 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);
    }
  }


  @Override
  protected void postProcess() throws Exception {
    results().put("result", "done.");
  }
  
  // pool example
  // another change

}