-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Okay.. So I'm a bit new to the ZK thing, as well as java. I know javascript fairly well, but not java.
I am trying to figure out how to connect to a MySQL database, access the information I need, and then output that.
I'm having a difficult time finding out exactly how to do that. Most of the stuff I have found is a bit kludgy, at least for me. And all of the ones I have found use a different method... so that makes me even more confused.
One that I have found is this... http://www.zkoss.org/smalltalks/contact/contact.dsp
but when I implement those things into my project, using eclipse, I just get tons of errors on all of the pages I make.
And do I really need 6 or 7 extra files just to access a database?
I am hopeful that someone here will be able to help me out some, and maybe provide some examples of what I should do.
I am using MySQL and Tomcat 6
EX: Database called bio
Table called Client
There are a few fields... id, name, address, phone number
I want to access the information based on the id, and then display that information
If anyone can help me out, I would greatly appreciate it.
Thanks
James,
What errors are you getting?
Basically (forgetting ZK for the moment):
MySQL database requires use of the MySQL JDBC driver... do you have that set correctly?
If you've tried a simple java application that just opens the database and does a select or update does everything work ok?
Frank
Simplist way, forget eclipse. Make sure
mysql-connector-java-5.1.7-bin
is in WEB-INF/lib
window.zul
... <zscript src="window.zs"/> <window use="MyWindow" id="win" height="100%"> ...
window.zs
import java.sql.*; public class MyWindow extends Window { Connection con=null; public void onCreate() { Class.forName("com.mysql.jdbc.Driver"); String url="jdbc:mysql://127.0.0.1:3306/bio"; con=DriverManager.getConnection(url,"root",""); alert("con="+con); stmt=con.prepareStatement("SELECT name FROM client LIMIT 2"); rs=stmt.executeQuery(); while(rs.next()){ alert(rs.getString(1)); } stmt.close(); con.close(); }
Hope that helps.
frankc01a - at the time, I wasn't getting any error... I didn't really understand the whole thing in general, sorry if my question was confusing.
bobbob - I tried what you said... and i got this error when i load window.zul ...
org.zkoss.zk.ui.UiException: Parse error at line 17, column 1. Encountered: <EOF>
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
org.zkoss.lang.Classes.newInstance(Classes.java:78)
org.zkoss.lang.Exceptions.wrap(Exceptions.java:164)
org.zkoss.zk.ui.UiException$Aide.wrap(UiException.java:46)
org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:103)
org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:292)
org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:858)
org.zkoss.zk.ui.impl.UiEngineImpl.execNonComponent(UiEngineImpl.java:728)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:547)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:557)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:525)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:492)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:374)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:296)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:230)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:167)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
Parse error at line 17, column 1. Encountered: <EOF>
bsh.Parser.generateParseException(Unknown Source)
bsh.Parser.jj_consume_token(Unknown Source)
bsh.Parser.Block(Unknown Source)
bsh.Parser.ClassDeclaration(Unknown Source)
bsh.Parser.BlockStatement(Unknown Source)
bsh.Parser.Line(Unknown Source)
bsh.Interpreter.Line(Unknown Source)
bsh.Interpreter.eval(Unknown Source)
bsh.Interpreter.eval(Unknown Source)
org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:100)
org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:292)
org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:858)
org.zkoss.zk.ui.impl.UiEngineImpl.execNonComponent(UiEngineImpl.java:728)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:547)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:557)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:525)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:492)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:374)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:296)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:230)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:167)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Asked: 2008-12-12 23:59:16 +0800
Seen: 375 times
Last updated: Dec 15 '08