Java know how much (110) database Insert Record

Source: Internet
Author: User
Tags gettext stmt

Insert data table records there are 3 different scenarios

I. Using the Statement object

The syntax for implementing an SQL statement that inserts a data table record is:

Insert into table name (field name 1, field name 2,......) Value (field value 1, field value 2, ...)

For example:

    INSERT into Ksinfo (test number, name, score, address, CV) value (' 200701 ', ' depopulation ' 534, ' Shanghai Ouyang Lu 218 Lane 4-1202 ', ')

Java program code that implements the same functionality is:

    sql = "Insert Intoksino (test number, name, score, address, CV)";    SQL= = sq1+ "Value ('" +txtno.gettxt () + ', ' "+txtname.gettext (0", ";     = sql+txtscore.gettext ();    SQL=sql+ ", '" +txtaddr.gettext () + "', '" +txtresume.gettext () +"')";    Stmt.executeupdate (SQL);

Two. Using the ResultSet object

Use the ResultSet object's method Movetoinsertrow () to move the data table cursor to the insertion position, enter the data, and insert the record with Method InsertRow (). For example, the following schematic code:

String sql= "SELECT * from Ksinfo";//Generating SQL statementsResultSet rs = stmt.executequery (SQL);//Get data table result setRs.movetoinsertrow ();//move a data table cursor to the insertion record locationRs.updatestring (1, ' 200701 ');//fill in the data into the test number fieldRs.updatestring (2, ' depopulation ');//fill in the data with the name fieldRs.updateint (3,534);//fill in the data into the score fieldRs.updatestring (4, ' Shanghai Ouyang Road 218 Lane 4-1202 ');//fill in the data into the Address fieldRs.updatestring (5, ");//fill in the data in the Resume field    Try{Rs.insertrow ();}Catch(Exception e) {};//finish inserting

Three. Using the Preparestatement object
  = "INSERT into Ksinfo (test number, name, score, address, CV) value (?,?,?,?  = connect.preparestatement (SQL); Pstmt.setstring ( 1, ' 200701 '); //  pstmt into the test number field. SetString (2, ' depopulation '); //  pstmt.setint (3,534); //  pstmt to the score field. SetString (4, ' Shanghai Ouyang Road 218 Lane 4-1202 '); //  pstmt. SetString (5, "); //  Fill in the Resume field with Data  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 updates

Java know how much (110) database Insert Record

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.