You are on page 1of 1

package myprojects.sample; import java.sql.*; public class Sample { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.

JdbcOdbcDriver"); Connection conn=DriverManager.getConnection("jdbc:odbc:s ample","sa","sa"); Statement stat=conn.createStatement(); boolean hasresult=stat.execute("select * from authors"); if(hasresult) { ResultSet rs=stat.getResultSet(); ResultSetMetaData rsmd=rs.getMetaData(); int noofcol =rsmd.getColumnCount(); for(int i=1;i<=noofcol;i++) { System.out.println(rsmd.getColumnName(i)); System.out.println(rsmd.getColumnTypeName(i)); } /* Here the students should write code to retrieve every column of every tuple and match it with the input keyword. * Matching must be based on datatype /* while(rs.next()) { System.out.println(rs.getString(1) +"\t\ t"); }*/ conn.close(); }

} catch(Exception e) { System.out.println("exception:"+e); } } }

You might also like