数据库操作语言HQL
来源:互联网 发布:ajax从cgi获取数据 编辑:程序博客网 时间:2024/06/10 00:09
package net.roseindia.hqlexamples;import java.util.Iterator;import java.util.List;import org.hibernate.Query;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import net.roseindia.model.*;/** * HQL Select Example In this example we are selecting all the customers from * the datastore */public class HQLSelect {public static void main(String[] args) throws Exception {/** Getting the Session Factory and session */SessionFactory factory = HibernateUtil.getSessionFactory();Session session = factory.getCurrentSession();/** Starting the Transaction */Transaction tx = session.beginTransaction();// Create Select Clause HQLString HQL_QUERY = "select c from Customer c";Query query = session.createQuery(HQL_QUERY);List result = query.list();for (Iterator it = result.iterator(); it.hasNext();) {Customer customer = (Customer) it.next();System.out.println("ID: " + customer.getId());System.out.println("Name: " + customer.getCustomerName());System.out.println("Phone: " + customer.getCustomerPhone());}/** Closing Session */session.close();}}
log4j.properties
log4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target=System.outlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%nlog4j.rootLogger=warn, stdout
package net.roseindia.model;import java.io.Serializable;import javax.persistence.Column;import javax.persistence.Entity;import javax.persistence.Id;import javax.persistence.Table;import javax.persistence.GeneratedValue;/** * @author Deepak Kumar * Hibernate HQL Tutorials */@Entity@Table(name="customers")public class Customer {@Id@GeneratedValue@Column(name = "id") private Integer id;@Column(name="customer_name")private String customerName;@Column(name="customer_phone")private String customerPhone;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getCustomerName() {return customerName;}public void setCustomerName(String customerName) {this.customerName = customerName;}public String getCustomerPhone() {return customerPhone;}public void setCustomerPhone(String customerPhone) {this.customerPhone = customerPhone;}}
源代码:http://pan.baidu.com/share/link?shareid=421815&uk=3878681452
原文:http://www.roseindia.net/hibernate/examples/hql/HQL-Select.html
参考:http://188029.net/hibernate/hib.html
- 数据库操作语言HQL
- HQL语言
- hql语言
- hql语言
- C语言操作数据库
- C语言操作数据库
- ORACLE 数据库操作语言
- Hibernate查询语言:HQL
- Hibernate 查询语言(HQL)
- Hibernate查询语言:HQL
- Hibernate查询语言:HQL
- Hibernate查询语言:HQL
- Hibernate查询语言:HQL
- Hibernate查询语言:HQL
- Hibernate查询语言:HQL
- Hibernate查询语言:HQL
- HQL查询语言基础!
- HQL查询语言基础!
- mtl_cst_txn_cost_details table
- Cocos2d 摸索[3]: 鼠标点击(手势触摸)事件
- 微录音--Android通话录音(vluyin-callrecorder)一款安卓通话录音软件
- Codeforces Round #181 (Div. 2) A题
- Hive体系结构
- 数据库操作语言HQL
- 基于xmpp协议的多端即时通讯方案
- 织梦未审核的文章仍然生成的问题
- github_项目DEMO创建
- URL特殊字符转义
- 异步加载统计图组件(jquery+css+div)
- Android Mms源码结构
- 开源 免费 java CMS - FreeCMS1.3-在线申报
- Cocos2d 摸索[4]: 定时器