Tutorial Project Java Web & SQL Server Part #1
A. Eclipse & ZK Framework
- Create File XML Read : https://qr-notes.blogspot.com/2021/08/create-file-xml-connection-java-zk.html
- Create Connection Database SQL Read : https://qr-notes.blogspot.com/2021/09/create-file-java-connection-database.html
-
Create Index.Zul
<?page title="index.zul"?> <window id="winmain" width="100%" height="100%"> <borderlayout height="100%"> <center border="0"> <borderlayout> <west style="text-align:center" title=".: MENU PROGRAM :. " maxsize="250" size="20%" collapsible="true"> <div style="background:#fafafa" vflex="1"> <tabbox sclass="tabbmenu_mod" id="tabsystem" width="100%" height="100%" mold="accordion-lite" visible="true"> <!-- HEADER TAB --> <tabs id="tabssystem" height="100%"> <tab label="HOME"/> <tab label="MASTER"/> <tab label="REPORT"/> </tabs> <tabpanels id="tabpanelsystem" height="100%"> <!-- SUB TAB HOME --> <tabpanel> <tree> <treechildren> <treeitem> <treerow> <treecell label="HOME" onClick="manuhome()"> </treecell> </treerow> </treeitem> </treechildren> </tree> </tabpanel> <!-- SUB TAB MASTER --> <tabpanel> <tree> <treechildren> <treeitem> <treerow> <treecell label="CUSTOMER" onClick="manucustomer()"> </treecell> </treerow> </treeitem> </treechildren> </tree> </tabpanel> <!-- SUB TAB REPORT --> <tabpanel> <tree> <treechildren> <treeitem> <treerow> <treecell label="CUSTOMER" onClick="menurptcustomer()"> </treecell> </treerow> </treeitem> </treechildren> </tree> </tabpanel> </tabpanels> </tabbox> </div> </west> <!-- Menu Side Center --> <center id="MainCenter" border="0" autoscroll="true" > <panel style="background:#fafafa;text-align:left"> <panelchildren> <tabbox id="tabApp" sclass="tab_app" width="100%"> <tabs id="tabs" mold=""> <tab id="tabStartUp" label="HOME" image="/images/home.png" style="color:#0F3B82; font-size: 10px; font-weight: bold;" /> </tabs> <tabpanels id="tabPanels"> <tabpanel id="tpStartUp"> <hbox> <space width="10px"/> <include id="maincenter2" src="content/home.zul" width="100%" height="100%" /> <space width="10px"/> </hbox> </tabpanel> </tabpanels> </tabbox> </panelchildren> </panel> </center> </borderlayout> </center> </borderlayout> <zscript> <![CDATA[ void manucustomer(){ tabStartUp.setLabel("CUSTOMER"); maincenter2.setSrc("content/customer.zul"); } void manuhome(){ tabStartUp.setLabel("HOME"); maincenter2.setSrc("content/home.zul"); } void menurptcustomer(){ tabStartUp.setLabel("REPORT"); maincenter2.setSrc("content/rptcustomer.zul"); } ]]> </zscript> </window>
-
Create Customer.zul
<?page title="customer" contentType="text/html;charset=UTF-8"?> <window id="win_customer" title="ENTRY CUSTOMER" border="normal" width="100%" use="com.apps.customer"> <grid height="150px" width="100%"> <columns> <column width="30%"></column> <column width="30%"></column> </columns> <rows> <row> <label value="ID CUSTOMER"></label> <textbox id="idcust" width="100px"></textbox> </row> <row> <label value="NAME CUSTOMER"></label> <textbox id="namecust" width="100px"></textbox> </row> <row> <label value="ADDRESS"></label> <textbox id="address" width="100px"></textbox> </row> <row> <label value=""></label> <button id="save" label="SAVE" onClick="win_customer.saveitem(idcust.getValue(),namecust.getValue(),address.getValue())"></button> </row> </rows> </grid> <listbox id="lstData" width="100%" emptyMessage="No Items Match Your Search" onCreate="win_customer.viewlist()" > <listhead> <listheader label="ID CUSTOMER" width="min"></listheader> <listheader label="NAME CUSTOMER" width="min"></listheader> <listheader label="ADDRESS CUSTOMER" width="min"></listheader> </listhead> </listbox> </window>
-
Create Customer.Java
package com.apps;
import com.apps.db.DBSQLConnection;
import java.sql.*;
import org.zkoss.zul.*;
import org.zkoss.zkex.zul.Jasperreport;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.util.JRStyledTextParser;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRCsvDataSource;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import com.lowagie.text.pdf.codec.Base64.InputStream;
import com.lowagie.text.pdf.codec.Base64.OutputStream;
public class customer extends Window {
String SQL;
public void saveitem(String cid, String cname, String caddress) throws Exception {
SQL="INSERT INTO CUSTOMER VALUES (?,?,?)";
Connection Conn = new DBSQLConnection().openConnection();
PreparedStatement prep = Conn.prepareStatement(SQL);
prep.setString(1, cid);
prep.setString(2, cname);
prep.setString(3, caddress);
prep.executeUpdate();
Conn.close();
Messagebox.show("Data has been saved successfully..","Data Saved",Messagebox.OK,Messagebox.INFORMATION);
viewlist();
}
public void viewlist() throws Exception {
Listbox lb=(Listbox)this.getFellow("lstData");
lb.getItems().clear();
SQL="SELECT * FROM CUSTOMER";
Connection Conn = new DBSQLConnection().openConnection();
Statement st = Conn.createStatement();
ResultSet rs = st.executeQuery(SQL);
while (rs.next()){
Listitem li = new Listitem();
li.setValue(rs.getString("idcust"));
li.appendChild(new Listcell(rs.getString("idcust")));
li.appendChild(new Listcell(rs.getString("namecust")));
li.appendChild(new Listcell(rs.getString("address")));
lb.appendChild(li);
}
rs.close();
st.close();
Conn.close();
}
public void rptcustomer() throws Exception {
SQL="SELECT * FROM CUSTOMER";
Connection Conn = new DBSQLConnection().openConnection();
Statement st = Conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM CUSTOMER");
Jasperreport rpt =(Jasperreport)this.getFellow("rpt");
rpt.setDatasource(new JRResultSetDataSource(rs));
rpt.setSrc("content/rpt/rptcustomer.jasper");
rpt.setType("pdf");
}
}
import com.apps.db.DBSQLConnection;
import java.sql.*;
import org.zkoss.zul.*;
import org.zkoss.zkex.zul.Jasperreport;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.util.JRStyledTextParser;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRParameter;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRCsvDataSource;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import com.lowagie.text.pdf.codec.Base64.InputStream;
import com.lowagie.text.pdf.codec.Base64.OutputStream;
public class customer extends Window {
String SQL;
public void saveitem(String cid, String cname, String caddress) throws Exception {
SQL="INSERT INTO CUSTOMER VALUES (?,?,?)";
Connection Conn = new DBSQLConnection().openConnection();
PreparedStatement prep = Conn.prepareStatement(SQL);
prep.setString(1, cid);
prep.setString(2, cname);
prep.setString(3, caddress);
prep.executeUpdate();
Conn.close();
Messagebox.show("Data has been saved successfully..","Data Saved",Messagebox.OK,Messagebox.INFORMATION);
viewlist();
}
public void viewlist() throws Exception {
Listbox lb=(Listbox)this.getFellow("lstData");
lb.getItems().clear();
SQL="SELECT * FROM CUSTOMER";
Connection Conn = new DBSQLConnection().openConnection();
Statement st = Conn.createStatement();
ResultSet rs = st.executeQuery(SQL);
while (rs.next()){
Listitem li = new Listitem();
li.setValue(rs.getString("idcust"));
li.appendChild(new Listcell(rs.getString("idcust")));
li.appendChild(new Listcell(rs.getString("namecust")));
li.appendChild(new Listcell(rs.getString("address")));
lb.appendChild(li);
}
rs.close();
st.close();
Conn.close();
}
public void rptcustomer() throws Exception {
SQL="SELECT * FROM CUSTOMER";
Connection Conn = new DBSQLConnection().openConnection();
Statement st = Conn.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM CUSTOMER");
Jasperreport rpt =(Jasperreport)this.getFellow("rpt");
rpt.setDatasource(new JRResultSetDataSource(rs));
rpt.setSrc("content/rpt/rptcustomer.jasper");
rpt.setType("pdf");
}
}
- Create rptCustomer.zul
<?page title="Report Customer"
contentType="text/html;charset=UTF-8"?>
<zk>
<window id="winrpt" title="Report Customer" width="100%" height="100%"
border="normal" use="com.apps.customer" onCreate="winrpt.rptcustomer()">
<div width="500px" height="500px" style="overflow:auto;" >
<jasperreport id="rpt" width="100%" height="90%" />
</div>
</window>
</zk>
<zk>
<window id="winrpt" title="Report Customer" width="100%" height="100%"
border="normal" use="com.apps.customer" onCreate="winrpt.rptcustomer()">
<div width="500px" height="500px" style="overflow:auto;" >
<jasperreport id="rpt" width="100%" height="90%" />
</div>
</window>
</zk>
-
Source Code :
https://github.com/qrnotes/Java-ZK-Framework-SQL-Server
B. Tutorial Java Web ZK Framework SQL Server
B. Tutorial Project Java (Form Entry)
No comments:
Post a Comment