this is what i am doing: but i need to know the each tables attribute name and their types(int etc). what this code does is simply print all the tables in the database .
Class.forName("com.mysql.jdbc.Driver").newInstance ();
Connection myCom = DriverManager.getConnection("jdbc:mysql://localhost/lab2_movies?user=nishant&password=wrox");
Statement stmt = myCom.createStatement();
DatabaseMetaData dbmd = null;
ResultSetMetaData rsmd = null;
ResultSet rst;
dbmd = myCom.getMetaData();
rst = dbmd.getTables( "lab2_movies", "%", "%",null);
rsmd = rst.getMetaData();
for( int i = 1; i <= rsmd.getColumnCount(); i++ ) {
System.out.print( rsmd.getColumnName(i) + "\t" );
System.out.print( rsmd.getColumnLabel(i) + "\t" );
}
System.out.print( "\n" );
System.out.println( "-------------------------------------------------------------------------------" );
while (rst.next()) {
for(int i = 1;i <= rsmd.getColumnCount(); i++ ) {
System.out.print( rst.getString(i) + "\t\t" );
System.out.print( "\n" );
}
}//while
|