Bookmark Topic Watch Topic
  • New Topic

To get the table in jdbc code  RSS feed

 
venkat
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
this is the code

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
public class GetRecords
{
public static void main(String [] args) throws SQLException
{
DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
Connection con=DriverManager.getConnection("Jdbc dbc:vendsn1","scott","tiger");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(" select * from department");
ResultSetMetaData rsmd=rs.getMetaData();
boolean b = rsmd.isSearchable(1);
while(rs.next())
{
System.out.println(rs.getRow());
System.out.println(rs.getInt(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rsmd.getColumnCount());
System.out.println(rsmd.getColumnDisplaySize(1));
System.out.println(rsmd.getColumnDisplaySize(2));
System.out.println(rsmd.getColumnDisplaySize(3));
System.out.println(rsmd.getColumnTypeName(1));
System.out.println(rsmd.getTableName(1));//to get the table name
System.out.println("-------");
}
rs.close();
stmt.close();
con.close();
}
}
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please don't post the same question in multipke forums, it creates duplicate conversations and wastes the time of the people trying to help you.

The duplicate is here, I'm asking for this duplicate to be closed.

Dave
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!