Componen, Fungsi & Event Framework zkoss - XI [ Data & Report - II ]

 

Berikut adalah contoh componen pada zkoss 

4. JDBC

<window title="JDBC" border="normal">

<zscript>{

import java.sql.*;

void submit() {

/*

//load driver and get a database connetion

//Note: It is usually better to use connection pool. Please consult

//the manual of your Web server. Or, refer to the Developer's Guide

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String url = "jdbc:odbc:Fred";

Connection con = DriverManager.getConnection(url,"myLogin", "myPassword");

PreparedStatement stmt = con.prepareStatement("INSERT INTO user values(?, ?)");

//insert what end user entered into database table

stmt.setString(1, name.value);

stmt.setString(2, email.value);

//execute the statement

stmt.executeUpdate();

//commit

con.commit();

//close the jdbc connection

con.close();

*/

}

}</zscript>

<grid>

<rows>

<row>Name : <textbox id="name"/></row>

<row>Email: <textbox id="email"/></row>

<row><button label="submit" onClick="submit()"/></row>

</rows>

</grid>

</window>


5. Hibernate

<zk>

<zscript>{

void submit() {

/*

Session session = HibernateUtil.currentSession();

Transaction tx = session.beginTransaction();

User aUser = new User();

//assign what end user entered into the persistence object.

aUser.setName(name.value);

aUser.setEmail(email.value);

session.save(aUser);

tx.commit();

HibernateUtil.closeSession();

*/

}

}</zscript>

<grid>

<rows>

<row>Name : <textbox id="name"/></row>

<row>Email: <textbox id="email"/></row>

<row><button label="submit" onClick="submit()"/></row>

</rows>

</grid>

</zk>


Reference : https://www.zkoss.org/zksandbox/#g2