Nutz Framework nutzdao-Custom SQL

Source: Internet
Author: User

1. normal Custom SQL statements


Create a custom SQL statement in Nutz with the implementation class ORG.NUTZ.DAO.SQLS of the Org.nutz.dao.sql.Sql interface . The code is as follows:


SQL SQL =sqls.create ("DELETE from t_abc WHERE name= ' Peter '");


2. Custom SQL statements that support placeholders


In Nutz, you can also build dynamic SQL statements in a placeholder way . The code is as follows:


SQL SQL =sqls.create ("DELETE from $table WHERE [email protected]");


Sql.vars (). Set ("Table", "T_ABC");


Sql.params (). Set ("Name", "Peter");


· Use $table to represent table names, replace them with T_ABC tables, and $ to represent variable placeholders


· Use @name to represent field names, replace with Peter, @ to represent parameter placeholders


· There is also a special placeholder, $condition,


Its usage is as follows:


SQL sql= sqls.create ("Select name from T_pet $condition");


Sql.setcondition (Cnd.where ("id", ">", 35));


as follows :


VoiddemoCondition2 (dao dao) {


SQL sql = sqls.create ("UPDATE t_pet [email protected] $condition");


Sql.params (). Set ("MasterID", 45);


Sql.setcondition (Cnd.wrap ("id>35"));


Dao.execute (SQL);


}


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.