Add, query, modify, and delete information

Source: Internet
Author: User
// Query all information. Public list <info> findallinfo () {list <info> List = new arraylist <info> (); try {datacon Dc = new datacon (); // database object connection con = dc. getconnction (); // connect to the database string SQL = "select I. *, U. * From info I, user u where I. userid = u. ID "; // query all users, user message information, password SQL statement preparedstatement PS = con. preparestatement (SQL); // process the SQL statement resultset rs = ps.exe cutequery (); // execute the query while (RS. next () {info in = new info (); // create a user message object in. setid (RS. getint ("I. ID "); // obtain the information Id passed to the info object in the database by column. setinfotitle (RS. getstring ("I. infotitle "); In. setinformation (RS. getstring ("I. information "); In. setuserid (RS. getint ("U. ID "); In. setusername (RS. getstring ("U. username "); list. add (in);} DC. closeall (RS, PS, con); // closes the database} catch (exception e) {e. printstacktrace ();} return list ;}

 
 
// Query all messages of a single user
// Query all messages of a single user. Public list <info> selectuserinfo (int id) {list <info> List = new arraylist <info> (); datacon Dc = new datacon (); // database object connection con = dc. getconnction (); // connect to the database string SQL = "select I. *, U. * From info I, user u where I. userid = u. ID and U. id =? "; // Query the username and password in the SQL statement try {preparedstatement PS = con. preparestatement (SQL); PS. setint (1, ID); // obtain the username resultset rs = ps.exe cutequery (); // execute the query while (RS. next () {info in = new info (); // create a user message object in. setid (RS. getint ("I. ID "); // obtain the information Id passed to the info object in the database by column. setinfotitle (RS. getstring ("I. infotitle "); In. setinformation (RS. getstring ("I. information "); In. setuserid (RS. getint ("U. ID "); In. setusername (RS. getstring ("U. username "); list. add (in) ;}} catch (exception e) {e. printstacktrace ();} return list ;}
 
// Query the information corresponding to a single message
Public info selectinfo (INT infoid) {info in = new info (); // create the user message object datacon Dc = new datacon (); // database object connection con = dc. getconnction (); // connect to the database string SQL = "select I. *, U. * From info I, user u where I. userid = u. ID and I. id =? "; // Query the information corresponding to a single message. The password SQL statement try {preparedstatement PS = con. preparestatement (SQL); PS. setint (1, infoid); // obtain the username resultset rs = ps.exe cutequery (); // execute the query while (RS. next () {In. setid (RS. getint ("I. ID "); // obtain the information Id passed to the info object in the database by column. setinfotitle (RS. getstring ("I. infotitle "); In. setinformation (RS. getstring ("I. information "); In. setuserid (RS. getint ("U. ID "); In. setusername (RS. getstring ("U. username ") ;}} catch (exception e) {e. printstacktrace ();} return in ;}

 

// Insert the public void insertuser (Info info) {datacon Dc = new datacon (); // database object connection con = dc. getconnction (); // connect to the database string SQL = "insert into Info (infotitle, information, userid) values (?,?,?) "; // Insert statement try {preparedstatement PS = con. preparestatement (SQL); // Execute SQL ps. setstring (1, info. getinfotitle (); // enter the user name PS to be passed in. setstring (2, info. getinformation (); // input the password PS to be passed in. setint (3, info. getuserid (); // pass in the password ps.exe cuteupdate (); // execute insert} catch (exception e) {e. printstacktrace () ;}}// update user information public void updateuser (Info info) {datacon Dc = new datacon (); // database object connection con = dc. getconnction (); // Connect to the database string SQL = "Update info set infotitle = ?, Information =? Where id =? "; // Update statement try {preparedstatement PS = con. preparestatement (SQL); // Execute SQL ps. setstring (1, info. getinfotitle (); // enter the user name PS to be passed in. setstring (2, info. getinformation (); PS. setint (3, info. GETID (); // pass in the password ps.exe cuteupdate (); // execute insert} catch (exception e) {e. printstacktrace () ;}}// delete user message public void deleteinfo (int id) {datacon Dc = new datacon (); // database object connection con = dc. getconnction (); // connect to the database string SQL = "delete from info where id =? "; // Delete statement try {preparedstatement PS = con. preparestatement (SQL); PS. setint (1, ID); // The deleted ID ps.exe cuteupdate ();} catch (exception e) {e. printstacktrace ();}}

 

 

 

 

Add, query, modify, and delete information

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.