Advanced Java: 06
Q. How to retrieve data from the database into a JDBC client?By Submitting "SELECT SQL" Statement we can retrieve data from the database. executeQuery() method of statement object is used to submit select statement to the DBMS.
- executeQuery() method takes SELECT SQL statement as a string argument.
- It returns Resultset object.
Q. Explain about executeQuery() Method?
- executeQuery() method is JDBC API Method.
- used to send SELECT Statement.
- It belongs to statement object.
- It's return type is ResultSet.
- It throws SQLException if anything goes wrong.
Q. Explain about ResultSet()?
- Object oriented representation of database records received from the DBMS (Database server) is nothing but Resultset Object.
- ResultSet Object is logically divided into 3 Partitions.
- Zero Record Area.
- Record Area.
- No Record Area.
- How resultset object internally look like?
- When ResultSet is open, a logical pointer known as Cursor points to zero record area of the resultset.
- When the cursor is pointing to ZERO Record Area or NO RECORD AREA, we should not try to read the data from the resultset. otherwise SQLException is raised.
- When the cursor is pointing to Record holding area then only you have to read the data. so how to move the cursor to record holding area as a programmer?
- java.sql.resultset has a method. "Next ()" to move the cursor.
- This method does two things: 1. Moves the cursor in forward direction by one record area. 2. After moving cursor, it returns true if record is present. It returns false if record is not there.
- ResultSet Object has a getter method to read data from the resultset record. these method takes column number of the resultset record as arguments and return the value.
After Execution of above code output will look like as follows.
No comments:
Post a Comment