Java SQL Table getIdNumber(String tableName)

Here you can find the source of getIdNumber(String tableName)

Description

get Id Number

License

Open Source License

Declaration

public static int getIdNumber(String tableName) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
    private static Connection connection = null;

    public static int getIdNumber(String tableName) {
        try {/*  w  w w.j  a  v  a 2 s  .c  om*/

            Statement stmt = connection.createStatement();

            ResultSet rs = stmt.executeQuery("SELECT * FROM " + tableName);
            int count = 0;
            while (rs.next()) {
                count++;
            }

            return count + 1;
        } catch (SQLException e) {
            System.out.println("Connection Failed! Check output console");
            e.printStackTrace();
            return -1;
        }
    }
}

Related

  1. exportTableData(String tableName, Connection con)
  2. getAllTableNames(Connection connection)
  3. getAllTables(Connection conn)
  4. getBatchResultMessage(String tableName, int rowIdx, int resultCode)
  5. getCount(Connection conn, String tableName)
  6. getImmutableDefaults()
  7. getLastCreatedEntry(Connection conn, String tableName)
  8. getMetaDataMap(Statement statement, String tableOrViewName)
  9. getNextId(Connection con, String table, String identityFieldName)