1 28 29 package com.caucho.amber.field; 30 31 import java.sql.Connection ; 32 import java.sql.ResultSet ; 33 import java.sql.SQLException ; 34 import java.sql.Statement ; 35 36 39 public class MaxGenerator extends Generator { 40 private String _table; 41 private String _column; 42 43 private String _sql; 44 45 48 public void setTable(String table) 49 { 50 _table = table; 51 } 52 53 56 public void setColumn(String column) 57 { 58 _column = column; 59 } 60 61 64 public void init() 65 { 66 _sql = "SELECT MAX(" + _column + ") FROM " + _table; 67 } 68 69 72 public long generate(Connection conn) 73 throws SQLException 74 { 75 Statement stmt = conn.createStatement(); 76 77 try { 78 ResultSet rs = stmt.executeQuery(_sql); 79 80 rs.next(); 81 82 long value = rs.getLong(1); 83 84 rs.close(); 85 86 return value; 87 } finally { 88 stmt.close(); 89 } 90 } 91 } 92 | Popular Tags |