menembus batas impian

Archive for November, 2011

Hibernate Query examples (HQL)


 

Hibernate created a new language named Hibernate Query Language (HQL), the syntax is quite similar to database SQL language. The main difference between is HQL uses class name instead of table name, and property names instead of column name.

HQL is extremely simple to learn and use, and the code is always self-explanatory.

1. HQL Select Query Example

Retrieve a stock data where stock code is “7277″.

Query query = session.createQuery("from Stock where stockCode = :code ");
query.setParameter("code", "7277");
List list = query.list();
Query query = session.createQuery("from Stock where stockCode = '7277' ");
List list = query.list();

2. HQL Update Query Example

Update a stock name to “DIALOG1″ where stock code is “7277″.

Query query = session.createQuery("update Stock set stockName = :stockName" +
    				" where stockCode = :stockCode");
query.setParameter("stockName", "DIALOG1");
query.setParameter("stockCode", "7277");
int result = query.executeUpdate();
Query query = session.createQuery("update Stock set stockName = 'DIALOG2'" +
    				" where stockCode = '7277'");
int result = query.executeUpdate();

3. HQL Delete Query Example

Delete a stock where stock code is “7277″.

Query query = session.createQuery("delete Stock where stockCode = :stockCode");
query.setParameter("stockCode", "7277");
int result = query.executeUpdate();
Query query = session.createQuery("delete Stock where stockCode = '7277'");
int result = query.executeUpdate();

4. HQL Insert Query Example

In HQL, only the INSERT INTO … SELECT … is supported; there is no INSERT INTO … VALUES. HQL only support insert from another table. For example

"insert into Object (id, name) select oo.id, oo.name from OtherObject oo";

Insert a stock record from another backup_stock table. This can also called bulk-insert statement.

Query query = session.createQuery("insert into Stock(stock_code, stock_name)" +
    			"select stock_code, stock_name from backup_stock");
int result = query.executeUpdate();

The query.executeUpdate() will return how many number of record has been inserted, updated or deleted.

 http://www.mkyong.com/hibernate/hibernate-query-examples-hql/

Iklan

Hibernate parameter binding examples


Without parameter binding, you have to concatenate the parameter String like this (bad code) :

String hql = "from Stock s where s.stockCode = '" + stockCode + "'";
List result = session.createQuery(hql).list();

Pass an unchecked value from user input to the database will raise security concern, because it can easy get hack by SQL injection. You have to avoid the above bad code and using parameter binding instead.

Hibernate parameter binding

There are two ways to parameter binding : named parameters or positional.

1. Named parameters

 This is the most common and user friendly way. It use colon followed by a parameter name (:example) to define a named parameter. See examples…
Example 1 – setParameter

The setParameter is smart enough to discover the parameter data type for you.

String hql = "from Stock s where s.stockCode = :stockCode";
List result = session.createQuery(hql)
.setParameter("stockCode", "7277")
.list();
Example 2 – setString

You can use setString to tell Hibernate this parameter date type is String.

String hql = "from Stock s where s.stockCode = :stockCode";
List result = session.createQuery(hql)
.setString("stockCode", "7277")
.list();
Example 3 – setProperties

This feature is great ! You can pass an object into the parameter binding. Hibernate will automatic check the object’s properties and match with the colon parameter.

Stock stock = new Stock();
stock.setStockCode("7277");
String hql = "from Stock s where s.stockCode = :stockCode";
List result = session.createQuery(hql)
.setProperties(stock)
.list();

2. Positional parameters

It’s use question mark (?) to define a named parameter, and you have to set your parameter according to the position sequence. See example…

String hql = "from Stock s where s.stockCode = ? and s.stockName = ?";
List result = session.createQuery(hql)
.setString(0, "7277")
.setParameter(1, "DIALOG")
.list();

This approach is not support the setProperties function. In addition, it’s vulnerable to easy breakage because every change of the position of the bind parameters requires a change to the parameter binding code.

String hql = "from Stock s where s.stockName = ? and s.stockCode = ?";
List result = session.createQuery(hql)
.setParameter(0, "DIALOG")
.setString(1, "7277")
.list();

Conclusion

In Hibernate parameter binding, i would recommend always go for “Named parameters“, as it’s more easy to maintain, and the compiled SQL statement can be reuse (if only bind parameters change) to increase the performance.

 

http://www.mkyong.com/hibernate/hibernate-parameter-binding-examples/

link update SIAP1.0.1


klik  link ini

kemudian klik unduh

kmd klik slow download

tunggu timer berjalan sampai angka nol,

trus keluar tombol unduh file sekarang klik aja tombol tesrsebut

hasil download copy kan ke drive c: di komputer anda di folder c:/SIAP1.0.1

menggantikan file SIDClient.jar yang sudah ada

Installasi PhpMyAdmin Manual ubuntu 11.10


langkah ini langkah yang sy pakai setelah

instal dr ubuntu Software Center dan pake command dr terminal: apt-get phpmyadmin

ga berbuah apa apa.

pertama:

instalasi dl apache, php dan mysql nya, langkahnya seperti dibawah ini;

Instalasi web server Apache

# apt-get install apache2

Instalasi database server MySQL

# apt-get install mysql-server

Instalasi php untuk web server Apache

# apt-get install php5

Instalasi MySQL untuk Apache

# apt-get install libapache2-mod-auth-mysql

# apt-get install php5-mysql

kedua

download phpMyAdmin-3.4.7-all-languages.tar.gz

 

ketiga

tar - xzvf phpMyAdmin-3.4.7-all-languages.tar.gz

setelah itu

rename hasil extrac nya

mv  phpMyAdmin-3.4.7-all-languages phpMyAdmin

sekarang tinggal copy foder phpMyAdmin ke /var/www

# cp -r phpMyAdmin /var/www

selesai! Alhamdulillah.