/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package db.providers;

import db.Db;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author lluis
 */
public class GenericDataProvider {
    
    public Integer getMaxTableId(String table)
    {
        Statement st = createStatement();
        String id = table + ".id";
        String sql = "SELECT max(" + id + ")+1 AS MAXID FROM " + table;
        try
        {
            ResultSet rs = st.executeQuery(sql);
            rs.first();
            Integer newId = new Integer(rs.getInt("MAXID"));
            if(newId.intValue() == 0)
            {
                newId = new Integer(1);
            }
            return newId;            
        }
        catch(Exception ex)
        {
            return new Integer(1);
        }
    }       
    
    protected Statement createStatement()
    {
        Db db = new Db();
        return db.createStatement();
    }      
}
