Friday, December 6, 2013

Liferay Tables Meta Data

Objective:

Get the Liferay tables meta data information

We can get tables Meta Data from JDBC.

Liferay providing DataAccess.java class from that we can open Connection to liferay default Database. Means we can connect to lportal data base.

Once we get the connection we pass simple select statement to statement object from that we can get Meta Data of table.

The following is example code to get Meta data of User_ tables in Liferay


java.sql.Connection con=null;
java.sql.Statement st=null;

try{
con=com.liferay.portal.kernel.dao.jdbc.DataAccess.getConnection();
st = con.createStatement();
java.sql.ResultSet rs = st.executeQuery("SELECT * FROM user_");
java.sql.ResultSetMetaData rsMetaData = rs.getMetaData();
int numberOfColumns = rsMetaData.getColumnCount();
System.out.println("resultSet MetaData column Count=" + numberOfColumns);
for (int i = 1; i <= numberOfColumns; i++) {
System.out.println("column MetaData ");
System.out.println("column number " + i);
System.out.println(rsMetaData.getColumnName(i));
}
}catch(Exception e){

}finally{
st.close();
con.close();
}



Note:
We need very much take care about connection closing.

Author
Meera Prince

0 comments :

Post a Comment

Recent Posts

Recent Posts Widget

Popular Posts