Use DbUtils for addition, deletion, modification, and query, and dbutils for addition, deletion, and modification

Source: Internet
Author: User

Use DbUtils for addition, deletion, modification, and query, and dbutils for addition, deletion, and modification

Commons-dbutils is an open-source JDBC tool library provided by the Apache organization. It is a simple encapsulation of JDBC and has very low learning costs. In addition, using dbutils can greatly simplify the workload of jdbc coding, at the same time, the program performance will not be affected. Therefore, dbutils has become the first choice for many companies that do not like hibernate.

/*** DbUtils usage: use DbUtils to add, delete, modify, and query operations * @ project_name Day12 * @ class_name DbUtilsDemo1 * @ author Dovinya * @ data 2014-8-27 11:07:09 * @ version 1 * @ notes * // * create database day12; use day12; create table table1 (id int primary key auto_increment, name varchar (20), salary double); insert into table1 values (null, 'zhang, 234.5 ); insert into table1 values (null, 'Li ', 234.5); insert into table1 values (Null, 'wang ', 3242); insert into table1 values (null, 'zhao', 32543); insert into table1 values (null, 'pan', 4654 ); insert into table1 values (null, 'hes', 4235); **/public class DbUtilsDemo1 {/** change using DbUtils */public void update () throws SQLException {// obtain the data source object QueryRunner runner = new QueryRunner (new ComboPooledDataSource (); runner. update ("update table1 set salary = 100") ;}@ Testpublic void add () throws SQLException {// obtain the data source object QueryRunner runner = new QueryRunner (new ComboPooledDataSource (); runner. update ("insert into table1 values (1 ,?,?) "," Lisi ", 1000) ;}@ Testpublic void delete () throws SQLException {// obtain the data source object QueryRunner runner = new QueryRunner (new ComboPooledDataSource (); runner. update ("delete from table1 where name = 'lisi'");} @ Testpublic void query () throws SQLException {// obtain the data source object QueryRunner runner = new QueryRunner (new ComboPooledDataSource (); List <User> list = runner. query ("select * from table1 where id <? ", New ResultSetHandler <List <User> () {@ Overridepublic List <User> handle (ResultSet rs) throws SQLException {List <User> list = new ArrayList <User> (); while (rs. next () {User user = new User (); user. setId (rs. getInt ("id"); user. setName (rs. getString ("name"); user. setSalary (rs. getDouble ("salary"); list. add (user) ;}return list ;}, 5); System. out. println (list); // here you can add breakpoint debugging observation }}



Use eclipse and mysql to add, delete, modify, and query small projects

It's very easy. If you ask a question, you can write it out. Why do you need to go online for help?

Java interface for addition, deletion, modification, and query

// Define the public interface SyUsersService {

/*** Add User */
Public void addSyUser (SyUsers syUsers );

/*** Obtain the registration information used based on the user name ***/
Public SyLeaguer isRightPasswordProtect (SyLeaguer syLeaguer );

/*** Update the User Password ***/
Public void updateSyUserPassword (SyUsers syUsers );

/*** User Logon verification ***/
Public boolean checkSyUserLogin (SyUsers syUsers );
/**
* Update user status * @ param loginName logon name * @ param state status code 0/1
* @ Return: whether the update is successful. true/flase
*/
Public boolean updateSyUserState (String loginName, Integer state );
/**
* Querying user information by PAGE
* @ Param pageNo page number
* @ Param pageSize page size
* @ Param hqlQueryRule query rule
* @ Return Page: the object to be queried by Page.
*/
Public Page querySyUserPage (int pageNo, int pageSize, HqlQueryRule hqlQueryRule );

/**
* Update the User Password
* @ Param loginName login name * @ param oldPassword old password
* @ Param newPassword: New Password
*/
Public void updateSyUserPassword (String loginName, String oldPassword, String newPassword );

/**
* Query users based on query rules
* @ See HqlQueryRule
* @ Param hqlQueryRule query rule
* @ Return result set list */
Public List querySyUser (HqlQueryRule hqlQueryRule );

/**
* Obtain user information based on the login name * @ param loginName
* @ Return
*/
Public SyUsers getSyUserByLoginName (String loginName );

/**
* Obtain user information based on the login name
* @ Param loginName
* @ Return
*/
Public boolean isRepeatUser (String loginName );

/**
* Update a user
* @ Param loginName
* @ Return
*/
Public void updateSyUsers (SyUsers syUsers );
}
// Implement the public class S... the remaining full text>
 

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.