0

help with accessing database. please.

asked 2008-12-12 23:59:16 +0800

james gravatar image james
255 2

updated 2008-12-13 00:01:13 +0800

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

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2008-12-13 15:05:39 +0800

frankc01a gravatar image frankc01a
39

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

link publish delete flag offensive edit

answered 2008-12-13 22:55:01 +0800

bobbob gravatar image bobbob
12

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.

link publish delete flag offensive edit

answered 2008-12-15 16:54:08 +0800

james gravatar image james
255 2

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 ...



exception

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)


link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-12-12 23:59:16 +0800

Seen: 375 times

Last updated: Dec 15 '08

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More