Data about data is known as MetaData
In JDBC Application development we have 3 catagerious of metadata they are
1. Meta Data about ResultSet
2. MetaData about Database Which we are using
3. MetaData about Parameters
1. Meta Data about Result Set
when we execute the select statement we get an object of ResultSet. an object of ResultSet Contains complete information about user specified database/ tablename
To find properties about table
java.sql.ResultSet
|
public ResultSetMetaData getMetaData()
ResultSetMetaData is an interface having following methods
a) public int getColumnCount()
b)public String getColumnName(int)
c)public int getColumnType(int)
d)public String getTableName(int)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
public class classmetadata {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system123");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp");
ResultSetMetaData rsmd=rs.getMetaData();
System.out.println("Print all column names....");
int count=rsmd.getColumnCount();
System.out.println("no of columns"+count);
for(int i=1;i<=count;i++)
{
System.out.println(rsmd.getColumnName(i));
}
System.out.println("====================");
}
}
Database metadata getting the complete details about the database product we are using.
DataBaseMetaData is one of the predefined interface whose object always gives
a)Database product name
b)Database product version
c)Getting the name of the Driver
d)Driver Version
e)Major Version of the Driver
f)Minor Version of the Driver
Methods in java.sql.DataBaseMetaData
In JDBC Application development we have 3 catagerious of metadata they are
1. Meta Data about ResultSet
2. MetaData about Database Which we are using
3. MetaData about Parameters
1. Meta Data about Result Set
when we execute the select statement we get an object of ResultSet. an object of ResultSet Contains complete information about user specified database/ tablename
To find properties about table
java.sql.ResultSet
|
public ResultSetMetaData getMetaData()
ResultSetMetaData is an interface having following methods
a) public int getColumnCount()
b)public String getColumnName(int)
c)public int getColumnType(int)
d)public String getTableName(int)
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
public class classmetadata {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system123");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from emp");
ResultSetMetaData rsmd=rs.getMetaData();
System.out.println("Print all column names....");
int count=rsmd.getColumnCount();
System.out.println("no of columns"+count);
for(int i=1;i<=count;i++)
{
System.out.println(rsmd.getColumnName(i));
}
System.out.println("====================");
}
}
DataBaseMetaData
Database metadata getting the complete details about the database product we are using.
DataBaseMetaData is one of the predefined interface whose object always gives
a)Database product name
b)Database product version
c)Getting the name of the Driver
d)Driver Version
e)Major Version of the Driver
f)Minor Version of the Driver
Methods in java.sql.DataBaseMetaData
- public String getDatabaseProductName()
- public String getDatabaseProductVersion()
- public String getDriverName()
- public int getDriverMajorVersion()
To create databasemetadata object
java.sql.Connection
|
public DatabaseMetaData getMetaData();
Parameter MetaData:
parameter metadata always deals with information about positional parameters(or) indexed parameters which we are using in pre-compiled queries are stored procedures.
java.sql.PreparedStatement
|
public ParameterMetaData getParameterMetaData()
No comments:
Post a Comment