Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC ResultSetMetaData

Have Programming Question? Ask it here!
 
 
 


vijay soma raju
ResultSetMetaData
2 Answer(s)      5 years and 10 months ago
Posted in : JDBC



Advertisement
View Answers

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 - JDBC
ResultSetMetaData  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
Get "Schema" of a table using "ResultSetMetaData"
GET "SCHEMA" OF A TABLE USING "RESULTSETMETADATA"   In this section, schema of a table will be fetched by using 'Resultset' object and 'ResultSetMetaData' object . For getting column name, we
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
Get Column names using Metadata in jsp
. ResultSetMetaData provides methods that are used to get the characteristics of ResultSet...; Statement stmt=null; ResultSetMetaData md; try{ Class.forName...() of ResultSetMetadata object returns the number of columns for the resultset from the query
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
JTABLE IS NOT RETIVING DATE FROM MS ACCESS........PLEZ PLEZ PLEZ HELP!!!!!!
Vector(); try { ResultSetMetaData rsmd=rs.getMetaData... Vector getNextRow(ResultSet rs, ResultSetMetaData rsmd)throws SQLException... = stmt.executeQuery( sql ); ResultSetMetaData md = rs.getMetaData(); int
Program - JSP-Servlet
"); ResultSetMetaData rsmd=rs.getMetaData(); int colcount...; EMPLOYEE NAME "); ResultSetMetaData rsmd=rs.getMetaData
Connection to database table in Oracle with Example
("SELECT * FROM employee");     ResultSetMetaData rsmd = rs.getMetaData
database
= st.executeQuery("SELECT * FROM "+tableNames+""); ResultSetMetaData md = rst.getMetaData
JDBC
= con.createStatement(); ResultSet rs = stmt.executeQuery( sql ); ResultSetMetaData
what is meta data in java
with it: DatabaseMetaData and ResultSetMetaData
How to add dynamic table in java
= con.createStatement(); ResultSet rs = stmt.executeQuery( sql ); ResultSetMetaData md
ResultSet
(query); ResultSetMetaData rsmd = rs.getMetaData
java
(); ResultSet rs = stmt.executeQuery( sql ); ResultSetMetaData md = rs.getMetaData
please help
(); ResultSetMetaData rsm=rs.getMetaData(); int rr=0; while
REPORT WITH JTABLE
"); ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); for (int i = 1; i
How To Display MS Access Table into Swing JTable - Java Beginners
( sql ); ResultSetMetaData md = rs.getMetaData(); int columns
About java
"); ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount
reply - Java Beginners
= st.executeQuery("SELECT * FROM tablename"); ResultSetMetaData rsMetaData
how to use views - Java Beginners
); ResultSetMetaData md = rs.getMetaData(); int
Need source code - Swing AWT
(); ResultSet rs = stmt.executeQuery( sql ); ResultSetMetaData md
Java Program - JDBC
= con.createStatement(); ResultSet rs = stmt.executeQuery( sql ); ResultSetMetaData
hi - Java Beginners
(); ResultSet rs = stmt.executeQuery( sql ); ResultSetMetaData md
JTable populate with resultset.
); ResultSetMetaData metaData = resultSet.getMetaData(); int columns.... ResultSetMetaData is used here to take information about the types and properties
parameter meta data - JDBC
;Hi friend, public interface ResultSetMetaData An object that can be used... * FROM table"); ResultSetMetaData rsmd = rs.getMetaData(); int
how to use dirivers - JDBC
"); ResultSetMetaData metaData=resultSet.getMetaData(); int numberOfColumns...("SELECT * FROM users"); ResultSetMetaData metaData=resultSet.getMetaData
jdbc - JDBC
"); ResultSetMetaData md = rs.getMetaData(); int col = md.getColumnCount... studentdetail"); ResultSetMetaData md = rs.getMetaData(); int col
JDBC Get Row Count
in a ResultSetMetaData object. The meta data call a getColumnCount ( ) return...); ResultSetMetaData metaData = rs.getMetaData(); int rowCount
Java program to get data type of column field
(); Above line of code gets ResultSetMetaData object which will be further used... and with the getColumnTypeName(index) method of ResultSetMetaData class. Here
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
add button to the frame - Swing AWT
,age from patientdetails1"); ResultSetMetaData rsmd = (ResultSetMetaData) rs.getMetaData(); // Get column names
Getting Column Names from a database table in Java
. Description of code: ResultSetMetaData: This is an interface of java.sql...): This method returns columns name (string type data) from ResultSetMetaData object
Get rows count and get columns names
);       ResultSetMetaData metaData = rs.getMetaData();             int rowCount
Show multiple identical rows into JTable from database
where name='"+name+"'"); ResultSetMetaData md
java swing (jtable)
= stmt.executeQuery( sql ); ResultSetMetaData md = rs.getMetaData(); int columns
How to use JTable with MS-Access
); ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); for (int i = 1
DATA BASE
); ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); for (int i
How to use JTable with MS-Access
); ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); for (int i = 1
Displaying files on selection of date.
+"'"); ResultSetMetaData md = rs.getMetaData(); int columns
How to refresh a jTable On adding or deleting record ....
(); ResultSet rs = stmt.executeQuery(sql); ResultSetMetaData md
resultset metadta
"); ResultSetMetaData md = rs.getMetaData(); while(rs.next
Help on this java code for online library search
= st.executeQuery(s); ResultSetMetaData md = rs.getMetaData(); int cols
java swing-action on checkbox selection
("Select * from employee"); ResultSetMetaData md = rs.getMetaData(); int
all sequences to create jdbc and how can i use jtable to display a single columns or multiple columns
"); ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); for (int i
 

 

 

DMCA.com