Monday, January 13, 2014

Java JDBC programming Example 13

//Note: create  a DSN in the name of sql that is pointing the table name limbs in the database with three String column  names things,legs,arms

import java.sql.*;

public class Jdbc13{
     public static void main(String s[]) throws Exception
Connection c =  DriverManager.getConnection("jdbc:odbc:sql");

Statement stmt = c.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM limbs");
ResultSetMetaData rsmd = rs.getMetaData();


System.out.println("No of columns :"+rsmd.getColumnCount());
System.out.println("is auto incrementing the columns ? :"+rsmd.isAutoIncrement(1));

System.out.println("is a column is case sensitive  ? :"+rsmd.isCaseSensitive(1));

System.out.println("Column label is   :"+rsmd.getColumnLabel(1));

System.out.println("Column name is   :"+rsmd.getColumnName(1));

System.out.println("Table name is     :"+rsmd.getTableName(1));

System.out.println("Column java type name :"+rsmd.getColumnType(1));

System.out.println("Column database type name :"+rsmd.getColumnTypeName(1));



Post a Comment