📄 jdbc.zul
字号:
<?xml version="1.0" encoding="UTF-8"?><!--jdbc.zul{{IS_NOTE Purpose: Description: History: Thu Nov 13 16:07:16 TST 2008, Created by Flyworld}}IS_NOTECopyright (C) 2008 Potix Corporation. All Rights Reserved.{{IS_RIGHT}}IS_RIGHT--><window id="demo" apply="org.zkoss.zkdemo.userguide.DemoWindowComposer"> <html><![CDATA[ <h4>JDBC</h4> <p>Presentation components do not assume any persistent technology. This example simply demostrate the possiblility to combine presentation component and database via JDBC.</p> ]]></html> <hbox> Note that we comment out the <toolbarbutton id="target" label="script" popup="details"/> on purpose because it will not run on our web site. </hbox> <separator /> <popup id="details" fulfill="target.onClick" width="600px"> <div style="border:1px solid #538BA2; background: #FFF; "> <html><![CDATA[<pre style='color:#000000;background:#ffffff;'><span style='color:#7f0055; font-weight:bold; '>import</span><span style='color:#7f0055; '> java</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; '>sql</span><span style='color:#7f0055; '>.</span><span style='color:#7f0055; font-weight:bold; '>*</span><span style='color:#7f0055; '>;</span> void submit() { <span style='color:#3f7f59; '>// load driver and get a database connetion</span> <span style='color:#3f7f59; '>// Note: It is usually better to use connection pool. Please consult</span> <span style='color:#3f7f59; '>// the manual of your Web server. Or, refer to the Developer's Guide</span> <span style='color:#7f0055; font-weight:bold; '>Class</span>.forName(<span style='color:#2a00ff; '>"sun.jdbc.odbc.JdbcOdbcDriver"</span>); <span style='color:#7f0055; font-weight:bold; '>String</span> url = <span style='color:#2a00ff; '>"jdbc:odbc:Fred"</span>; <span style='color:#7f0055; font-weight:bold; '>Connection</span> con = <span style='color:#7f0055; font-weight:bold; '>DriverManager</span>.getConnection(url, <span style='color:#2a00ff; '>"myLogin"</span>, <span style='color:#2a00ff; '>"myPassword"</span>); <span style='color:#7f0055; font-weight:bold; '>PreparedStatement</span> stmt = con .prepareStatement(<span style='color:#2a00ff; '>"INSERT INTO user values(?, ?)"</span>); <span style='color:#3f7f59; '>// insert what end user entered into database table</span> stmt.setString(1, name.value); stmt.setString(2, email.value); <span style='color:#3f7f59; '>// execute the statement</span> stmt.executeUpdate(); <span style='color:#3f7f59; '>// commit</span> con.commit(); <span style='color:#3f7f59; '>// close the jdbc connection</span> con.close(); }</pre> ]]></html> </div> </popup>
<tabbox width="100%" tabscroll="false">
<tabs>
<tab id="demoView" label="Demo"/>
<tab id="srcView" label="View Source"/>
</tabs>
<tabpanels>
<tabpanel>
<window id="view">
</window>
</tabpanel>
<tabpanel>
<panel>
<panelchildren>
<textbox id="codeView" class="code" rows="20" width="95%">
<attribute name="value"><![CDATA[<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>
]]></attribute>
</textbox>
</panelchildren>
<toolbar mold="panel">
<button id="tryBtn" label="Try me!"/>
<button id="reloadBtn" label="Reload" height="18px"/>
</toolbar>
</panel>
</tabpanel>
</tabpanels>
</tabbox></window>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -