Java Learning Notes (55)-meta data metadata and scrollable result sets

Source: Internet
Author: User

Metadata meta data
/ * Metadata meta data * / Public classTest03 {Connection conn =NULL; PreparedStatement pstmt=NULL; ResultSet rs =NULL; Public void Test() {conn=dbutil.getconnection ();Try{DatabaseMetaData dbmd=conn.getmetadata ();//Get database meta dataSystem. out. println (Dbmd.getdatabaseproductname ()); System. out. println (Dbmd.getdatabaseproductversion ()); System. out. println (Dbmd.getdrivername ()); System. out. println (Dbmd.getdriverversion ()); Pstmt=conn.preparestatement ("Select Username,password from User"); Rs=pstmt.executequery ();//Get result set meta dataResultSetMetaData Rsmd=rs.getmetadata (); System. out. println (Rsmd.getcolumncount ()); System. out. println (Rsmd.getcolumnname (1)); System. out. println (Rsmd.getcolumnname (2)); }Catch(SQLException e)        {E.printstacktrace (); }    } Public Static void Main(string[] args) {NewTest03 (). Test (); }}
Scrollable result set
/ * Scrollable result set * /public class TEST04 {Connection conn = null;PreparedStatement pstmt = null;ResultSet rs = null;Insert a record when reading to a specified user public void test01 () {String sql ="SELECT * from User";try {conn = Dbutil. getconnection();PSTMT = conn. Preparestatement(SQL, ResultSet. TYPE_scroll_insensitive, ResultSet. CONCUR_updatable);rs = pstmt. ExecuteQuery();//scrollable result set, can update tablewhile (RS. Next()) {String name = rs. getString("username");if (name. Equals("Tom") {//To determine the currently read user//Move the cursor to the Insert row, the Insert row is actually a buffer to prepare the data RS. Movetoinsertrow();Rs. updatestring("username","Alex");Rs. updatestring("Password","999");Data in the commit buffer RS. InsertRow();System. out. println("Insert User success!" ");Moves the cursor to the current line, which is the record before the record is inserted RS. Movetocurrentrow();} System. out. println(RS. GetInt(1) +","+ RS. getString(2) +","+ RS. getString(3));}} catch (SQLException e) {E. Printstacktrace();} finally {Dbutil. CloseAll(RS, PSTMT, conn);}}//delete the specified user public void test02 () {String sql ="SELECT * from User";try {conn = Dbutil. getconnection();PSTMT = conn. Preparestatement(SQL, ResultSet. TYPE_scroll_insensitive, ResultSet. CONCUR_updatable);rs = pstmt. ExecuteQuery();while (RS. Next()) {String name = rs. getString("username");if (name. Equals("BBB")) {RS. DeleteRow();//delete current lineRs. Next();//Remove the cursor downSystem. out. println("Delete User Success");} System. out. println(RS. GetInt(1) +","+ RS. getString(2) +","+ RS. getString(3));}} catch (SQLException e) {E. Printstacktrace();} finally {Dbutil. CloseAll(RS, PSTMT, conn);}}//move cursor public void test03 () {String sql ="SELECT * from User";try {conn = Dbutil. getconnection();PSTMT = conn. Preparestatement(SQL, ResultSet. TYPE_scroll_insensitive, ResultSet. CONCUR_updatable);rs = pstmt. ExecuteQuery();while (RS. Next()) {String name = rs. getString("username");if (name. Equals("s001")) {RS. Relative(3);} System. out. println(RS. GetInt(1) +","+ RS. getString(2) +","+ RS. getString(3));}} catch (SQLException e) {E. Printstacktrace();} finally {Dbutil. CloseAll(RS, PSTMT, conn);}} public static void Main (string[] args) {new Test04 (). Test03 ();}}

Java Learning Notes (55)-meta data metadata and scrollable result sets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.