WDD_lec_17 - Design & Development Web Lec - 17 1 Design...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Web Lec - 17
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Web More on JDBC
Background image of page 2
3 Web Meta Data
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JDBC 4 Umair Javed©2005 Meta Data What if you want to know: How many columns are in the result set? What is the name of a given column? Are the column names case sensitive? What is the data type of a specific column? What is the maximum character size of a column? Can you search on a given column?
Background image of page 4
JDBC 5 Umair Javed©2005 Using ResultSetMetaData Idea From a ResultSet ( the return type of executeQuery ), derive a ResultSetMetaData object Use that object to look up the number, names, and types of columns
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JDBC 6 Umair Javed©2005 Useful ResultSetMetaData Methods getColumnCount ( ) Returns the number of columns in the result set getColumnDisplaySize (int) Returns the maximum width of the specified column in characters getColumnName(int) / getColumnLabel (int) The getColumnName method returns the database name of the column The getColumnLabel method returns the suggested column label for printouts getColumnType (int) Returns the SQL type for the column to compare against types in java.sql.Types
Background image of page 6
JDBC 7 Umair Javed©2005 Example Code: MetaDataEx using ResultSetMetaData import java.sql.*; public class MetaDataEx { public static void main ( String args[ ]) { try { Class.forName(“Driver name”); Connection con = DriverManager.getConnection(url, usr, pwd); String sql = “SELECT * FROM Person”; PreparedStatement pStmt = con.prepareStatement(sql); ResultSet rs = pStmt.executeQuery( );
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JDBC 8 Umair Javed©2005 Example Code: MetaDataEx (cont.) using ResultSetMetaData ResultSetMetaData rsmd = rs.getMetaData(); int numColumns = rsmd.getColumnCount(); System.out.println(“Number of Columns:” + numColumns); String cName; for (int i=1; i <= numColumns; i++) { cName = rsmd.getColumnName (i); System.out.print(cName); System.out.print("\t"); } // changing line System.out.println("");
Background image of page 8
JDBC 9 Umair Javed©2005 Example Code: MetaDataEx (cont.) using ResultSetMetaData
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 34

WDD_lec_17 - Design &amp; Development Web Lec - 17 1 Design...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online