Check if JDBC always returns the generated key - Java JDBC

Java examples for JDBC:Key

Description

Check if JDBC always returns the generated key

Demo Code

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Main {
    public static void main(String[] args) {

        try {// www .j  a  va2  s . c  om
            Connection con = DriverManager.getConnection(
                    "jdbc:derby://localhost:1527/contact", "userName", "password");

            System.out.println("Schema: " + con.getSchema());
            DatabaseMetaData metaData = con.getMetaData();
 
            System.out.println("Auto Generated Keys: " + metaData.generatedKeyAlwaysReturned());

       } catch (SQLException ex) {
            ex.printStackTrace();
       }
    }
}

Related Tutorials