ResultSetMetaData: isReadOnly(int column) : ResultSetMetaData « java.sql « Java by API






ResultSetMetaData: isReadOnly(int column)

 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

public class Main {
  public static void main(String[] args) throws Exception {
    Connection conn = getConnection();

    Statement st = conn.createStatement();

    st.executeUpdate("create table survey (id int,myDate DATE);");
    String INSERT_RECORD = "insert into survey(id, myDate) values(?, ?)";

    PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD);
    pstmt.setString(1, "1");
    java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
    pstmt.setDate(2, sqlDate);

    pstmt.executeUpdate();

    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    ResultSetMetaData rsmd = rs.getMetaData();

    int numCols = rsmd.getColumnCount();

    System.out.print("\t");
    for (int i = 1; i <= numCols; i++) {
      System.out.println(rsmd.getColumnLabel(i));
    }

    System.out.print("\nAuto Increment\t");
    for (int i = 1; i <= numCols; i++) {
      System.out.println(rsmd.isAutoIncrement(i));
    }
    for (int i = 1; i <= numCols; i++) {

      System.out.println(rsmd.isCaseSensitive(i));
    }
    System.out.print("\nSearchable\t");
    for (int i = 1; i <= numCols; i++) {

      System.out.println(rsmd.isSearchable(i));
    }
    System.out.print("\nCurrency\t");
    for (int i = 1; i <= numCols; i++) {
      System.out.println(rsmd.isCurrency(i));
    }
    System.out.print("\nAllows nulls\t");
    for (int i = 1; i <= numCols; i++) {

      System.out.println(rsmd.isNullable(i));
    }
    System.out.print("\nSigned\t");
    for (int i = 1; i <= numCols; i++) {

      System.out.println(rsmd.isSigned(i));
    }
    System.out.print("\nRead only\t");
    for (int i = 1; i <= numCols; i++) {

      System.out.println(rsmd.isReadOnly(i));
    }
    System.out.print("\nWritable\t");
    for (int i = 1; i <= numCols; i++) {

      System.out.print(rsmd.isWritable(i));
    }
    System.out.print("\nDefinitely Writable\t");
    for (int i = 1; i <= numCols; i++) {

      System.out.println(rsmd.isDefinitelyWritable(i));
    }

    conn.close();
  }

  private static Connection getConnection() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    String url = "jdbc:hsqldb:mem:data/tutorial";

    return DriverManager.getConnection(url, "sa", "");
  }
}

   
  








Related examples in the same category

1.ResultSetMetaData.columnNoNulls
2.ResultSetMetaData.columnNullable
3.ResultSetMetaData.columnNullableUnknown
4.ResultSetMetaData: getCatalogName(int column)
5.ResultSetMetaData: getColumnCount()
6.ResultSetMetaData: getColumnDisplaySize(int column)
7.ResultSetMetaData: getColumnClassName(int column)
8.ResultSetMetaData: getColumnLabel(int column)
9.ResultSetMetaData: getColumnName(int column)
10.ResultSetMetaData: getColumnType(int column)
11.ResultSetMetaData: getPrecision(int column)
12.ResultSetMetaData: getScale(int column)
13.ResultSetMetaData: getSchemaName(int column)
14.ResultSetMetaData: getTableName(int column)
15.ResultSetMetaData: isAutoIncrement(int column)
16.ResultSetMetaData: isCaseSensitive(int column)
17.ResultSetMetaData: isCurrency(int column)
18.ResultSetMetaData: isDefinitelyWritable(int column)
19.ResultSetMetaData: isNullable(int column)
20.ResultSetMetaData: isSearchable(int column)
21.ResultSetMetaData: isSigned(int column)
22.ResultSetMetaData: isWritable(int column)