// 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