Java know how much (111) Several important Java database access classes and interfaces

Source: Internet
Author: User
Tags gettext

There are also 3 options for modifying data table records.

I. Using the Statement object

The syntax for implementing SQL statements that modify data table records is:
Update table name SET field Name 1 = field value 1, field name 2 = field value 2,......where specific condition
For example:

    Update Ksinfo Set name = ' Zhang Wei ' where name = ' depopulation '

Create an SQL statement first, and then 砶 call the Executeupdate () method of the Statement object. For example

1     sql = "Update ksinfo set name = '" +Txtname.gettext (); 2     sql = SQL + ", score =" +txtscore.gettext (); 3     sql = SQL + ", address = '" +Txtaddr.gettext (); 4     Sql= sql+ "',, CV = '" +txtresume.gettext () + "' where test number =" +txtno.gettext (); 5     Stmt.executeupdate (SQL);

Two. Using the ResultSet object

First set up the ResultSet object, then directly set the record field values, modify the data table records. For example

1     String sql = "SELECT * from ksinfo where name = ' depopulation '"; // Generating SQL statements 2     ResultSet rs = stmt.executequery (SQL); // Get data table result set 3     if (Rs.next ()) {4         rs.updatestring (2, ' Zhang Wei '); 5         Try {Rs.updaterow ();} Catch (Exception e) {} 6     }

Three. Using the Preparestatement object

When creating SQL statements, use parameters temporarily. Represents a value, which is then generated by the SQL statement object and the Preparestatement object is then implemented to update the record by setting the actual parameters. Schematic code:

1     sql = "Update ksinfo set name =?" WHERE name = ' depopulation '; 2     Preparestatement pstmt = connect.preparestatement (sql); 3     Pstmt.setstring (2, ' Zhang Xiao Wei '); // fill in the data with the name field 4     Pstmt.executeupdate ();

Series Articles:

Java know how much (top)Java know how much (medium)Java knows how many () Java vectors (vector) and their applicationsJava know how much (79) hash table and its applicationJava know how much (80) graphical Interface design basicsJava know how much (81) frame window BasicsJava know how much (82) Introduction to tags, buttons, and button eventsJava know how much (83) Panel Basics: JPanel and JScrollPaneJava know how much (84) layout design of graphical interfaceJava know how much (85) text box and text areaJava know how much (86) input and output of text box and text areaJava know how much (87) Select boxes and radio buttonsJava know how many (88) lists and combo boxesJava know how many (89) lists and combo boxesJava know how much (90) menuJava know how much (91) dialog boxJava know how much (92) scroll barJava know how much (93) mouse EventsJava know how much (94) keyboard EventsJava know how much (95) Drawing BasicsJava know how much (96) set the font and color of the drawingJava know how much (97) Drawing Mode OverviewHow much Java knows (98) the drawing method of the Graphics classJava know how much (graphics2d) the drawing method of the classJava know how much (100) Image processing BasicsJava know how much (101) image buffering TechnologyJava know how much (102) Multimedia FoundationJava know how much (103) network programming IP address and InetAddress classJava know how much (104) the Uniform Resource Locator URL for network programmingJava know how much (105) socket (socket)Java know how much (106) program and database connectionJava know how much (107) Several important Java database access classes and InterfacesJava know how much (108) database query IntroductionJava know how much (109) database updatesJava know how much (110) database insert record

Java know how much (111) Several important Java database access classes and interfaces

Related Article

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.