Java SQL Table Column generateKey(Statement statement, String TableName, String KeyColumn)

Here you can find the source of generateKey(Statement statement, String TableName, String KeyColumn)

Description

generate Key

License

Apache License

Declaration

public static int generateKey(Statement statement, String TableName, String KeyColumn) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.*;

public class Main {
    public static int generateKey(Statement statement, String TableName, String KeyColumn) throws SQLException {
        String sql = "SELECT MAX(" + KeyColumn + ") FROM  " + TableName;

        return getQueryInt(statement, sql);
    }//from w  ww  . jav a 2  s . c om

    public static int getQueryInt(Statement statement, String pSql) throws SQLException {
        ResultSet rs = statement.executeQuery(pSql);
        int ret = 0;
        if (!rs.next())
            return (1);
        return (rs.getInt(1));
    }
}

Related

  1. columnExists(Connection con, String tableName, String columnName)
  2. columnExists(Connection connection, String table, String column)
  3. columnLabels(final ResultSet results)
  4. containsColumn(ResultSet rs, String columnName)
  5. extractColumnTypeName(ResultSetMetaData resultSetMetaData, int index)
  6. getAllFromSensorDb( final Connection jdbcConnection, final String tableName, final String orderByColumn)
  7. getColumn(ResultSet result, int col)
  8. getColumnDisplaySize(int col, ResultSetMetaData rsmd)
  9. getColumnIndexFromColumnName(ResultSetMetaData metaData, String columnName)