October 3, 2008 at 12:32 PM
Hi,
JDBC provides four interfaces that deal with database metadata
* java.sql.DatabaseMetaData: about the database as a whole: table names, table indexes, database product name and version, and actions the database supports.
* java.sql.ResultSetMetaData: about the types and properties of the columns in a ResultSet object.
* java.sql.ParameterMetaData: about the types and properties of the parameters in a PreparedStatement object.
* javax.sql.RowSetMetaData: about the columns in a RowSet object.
DatabaseMetaData
1. Metadata is data about data.
2. Database metadata is information about a database.
3. Database metadata provides information about the structure of a database and its tables, views, and stored procedures.
ResultSetMetaData
An object that can be used to get information about the types and properties of the columns in a ResultSet object. The following code fragment creates the ResultSet object rs, creates the ResultSetMetaData object rsmd, and uses rsmd to find out how many columns rs has and whether the first column in rs can be used in a WHERE clause.
ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM StudentDetail");
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
boolean b = rsmd.isSearchable(1);
----------------------------------------
Visit for more information.
http://www.roseindia.net/jdbc/Thanks.
Amardeep
October 3, 2008 at 12:35 PM
Hi friend,
public interface ResultSetMetaData
An object that can be used to get information about the types and properties of the columns in a ResultSet object.
For Example :
import java.sql.*;
public class ColumnName{
public static void main(String[] args) {
System.out.println("Getting Column Names Example!");
Connection con = null;
String url = "jdbc:
mysql://localhost:3306/";;
String db = "userdetails";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM employee_master");
ResultSetMetaData md = rs.getMetaData();
int col = md.getColumnCount();
System.out.println("Number of Column : "+ col);
System.out.println("Columns Name: ");
for (int i = 1; i <= col; i++){
String col_name = md.getColumnName(i);
System.out.println(col_name);
}
}
catch (SQLException s){
System.out.println("SQL statement is not executed!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
DatabaseMetaData:
This is an interface of java.sql package that implemented by driver vendors. It tells about the data of the data like number of tables in the database , the information about the columns of the table.
For Example :
import java.sql.*;
public class AllTableName{
public static void main(String[] args) {
System.out.println("Listing all table name in Database!");
Connection con = null;
String url = "jdbc:
mysql://localhost:3306/";;
String db = "userdetails";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
try{
DatabaseMetaData dbm = con.getMetaData();
String[] types = {"TABLE"};
ResultSet rs = dbm.getTables(null,null,"%",types);
System.out.println("Table name:");
while (rs.next()){
String table = rs.getString("TABLE_NAME");
System.out.println(table);
con.close();
}
}
catch (SQLException s){
System.out.println("No any table in the database");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
For more information on JDBC-Mysql visit to :
http://www.roseindia.net/jdbc/jdbc-mysql/Thanks
Related Tutorials/Questions & Answers:
ResultSetMetaData - JDBCResultSetMetaData Explain about
ResultSetMetaData,what... of a database and its tables, views, and stored procedures.
ResultSetMetaData... the ResultSet object rs, creates the
ResultSetMetaData object rsmd, and uses rsmd
Advertisements
column count using metadata ,we will get column count using "
resultsetmetadata ".Using
resultset....
The
ResultSetMetaData object can be obtained by invoking getMetaData() method on
ResultSet... = st.executeQuery("SELECT * FROM employee");
ResultSetMetaData rsmd
Get Column Count using ResultSet in SQL of columns in a ResultSet.
The
ResultSetMetaData object can be obtained by invoking...;);
6. Getting
ResultSetMetaData
objectResultSet has method getMetaData
java - JDBC provides
meta information of the result set.
ResultSetMetaData rsmd = rs.getMetaData();
7. getColumnCount() method on
ResultSetMetaData object... of Columns="+totalCol);
8. getTableName() method on
ResultSetMetaData jdbc interview question. JDBC RowSet Example
ResultSetMetaData:
ResultSetMetaData is a class which.... JDBC details interrogation can be done by using
ResultSetMetaData. It includes... they contain etc.
ResultSetMetaData Example
Java Display Tables of Database
java - Java Beginners java.awt.event.*;
public class
ResultSetMetadata implements ActionListener{
JFrame f...;
GridBagLayout gbl;
GridBagConstraints gbc;
ResultSetMetadata(){
f=new JFrame("Table...[])
{
ResultSetMetadata pro=new
ResultSetMetadata();
pro.dis();
}
public void actionPerformed
jsp");
ResultSetMetaData rsmd = rs.getMetaData();
int numColumns = rsmd.getColumnCount
Get Column names using Metadata in jsp.
ResultSetMetaData provides methods that are used to
get the
characteristics...;
ResultSetMetaData md;
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc... of the resultset.
7) The method md.getColumnCount() of
ResultSetMetadata object returns
Program - JSP-Servlet ");
ResultSetMetaData rsmd=rs.getMetaData();
int colcount...; EMPLOYEE NAME ");
ResultSetMetaData rsmd=rs.getMetaData
Java Program - JDBC = con.createStatement();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData About java * from data");
ResultSetMetaData md = rs.getMetaData();
int columns
REPORT WITH JTABLE");
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for (int i = 1; i
please help();
ResultSetMetaData rsm=rs.getMetaData();
int rr=0;
while
java();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData md = rs.getMetaData
ResultSet(query);
ResultSetMetaData rsmd = rs.getMetaData
JDBC = con.createStatement();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData database = st.executeQuery("SELECT * FROM "+tableNames+"");
ResultSetMetaData md = rst.getMetaData
jdbc - JDBC");
ResultSetMetaData md = rs.getMetaData();
int col = md.getColumnCount... studentdetail");
ResultSetMetaData md = rs.getMetaData();
int col
how to use dirivers - JDBC");
ResultSetMetaData metaData=resultSet.getMetaData();
int numberOfColumns...("SELECT * FROM users");
ResultSetMetaData metaData=resultSet.getMetaData
parameter meta data - JDBC;Hi friend,
public interface
ResultSetMetaData
An object that can be used... * FROM table");
ResultSetMetaData rsmd = rs.getMetaData();
int
JDBC Get Row Count of the columns in a
ResultSetMetaData
object. The meta data call... = st.executeQuery(sql);
ResultSetMetaData metaData = rs.getMetaData
JTable populate with resultset.);
ResultSetMetaData metaData = resultSet.getMetaData();
int columns....
ResultSetMetaData is used here to take information about the types and properties
Getting Columns Names using Servlets a reference of
ResultSetMetaData object and we will get
it only when if we have... of the ResultSet. By the help of the ResultSet
we can get the object of
ResultSetMetaData... getColumnsNames() of the
ResultSetMetaData
interface. The output will be displayed to you
Getting Number of Columns of
ResultSetMetaData object
and we will get it only when if we have... of
ResultSetMetaData.
We will get it by calling the method getMetaData() of the ResultSet... by the
method getColumnsCount() of the
ResultSetMetaData interface. This
method
JTable - Java Beginners * from sdmpl");
ResultSetMetaData md = res2.getMetaData();
int columns... );
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount
java - JDBC sheet$]";
ResultSet rs=st.executeQuery(query);
ResultSetMetaData md
java - IDE Questions = con.createStatement();
ResultSet rs = stmt.executeQuery( sql );
ResultSetMetaData md
printout problem= st.executeQuery("Select * from data");
ResultSetMetaData md = rs.getMetaData
Beans in Swings table");
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for (int