-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi guy !
firstly i dont speak english very well. so forgive me for my mistakes.
i work with zk and eclipse and oracle . I try to make a login window.
I already test the connection with oracle .
Driver , url and my query sql work well. when i run it by doing a Run Java Application (it mean that i do a main in my class java).
But when i remove the main and try to make the connection with zul login file ;
i got and error ;
Drive not found ...
This is the structure of my java class.
public static String verifiCoord (Textbox log2,Textbox pd2) { //je linitialise pas car la methode appele est en static . String login = log2.getValue(); String pwd = pd2.getValue(); ResultSet rs; try { String driverName = "oracle.jdbc.driver.OracleDriver"; Class.forName(driverName); System.out.println("driver trouveeeeeeeee"); } catch (ClassNotFoundException e) { System.out.println("Driver classe non trouveeeeeeeeeee"); } try{ connect=DriverManager.getConnection("jdbc:oracle:thin:@dellprecision:1521:metuu","scott","azerty"); }catch(SQLException e){ System.out.println("Connection impossibleeeeeeeeee base de donnees" +e); } try{ Statement s=connect.createStatement(); String sql="select login from usersesion where login ='"; sql+=login; sql+="'"; sql+="and pwd='"; sql+=pwd; sql+="'"; rs=s.executeQuery(sql); retourChaine = rs.getString(1); s.close(); }catch(SQLException s){ System.out.println("erreur requete"+s.getMessage()); } System.out.println("valeur de ma chaine"+retourChaine); return retourChaine; }
Here is my zul file
<?page title="Authentification Utilisateur" ?> <window title="Authentification Utilisateur" width="300px" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:zk="http://www.zkoss.org/2005/zul" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul" id="auth_window" border="none"> <zscript > <![CDATA[//@IMPORT import course.Login; import course.Entry;]]> <![CDATA[//@DECLARATION Entry e = new Entry(); Login l = new Login(); ]]> </zscript> <grid> <rows> <row><label value="Nom d'utilisateur"/></row> <row><textbox id="username"></textbox></row> <row> <label value="Mot de passe"/></row> <row><textbox id="pwd"></textbox></row> <row><button label="Se connecter" onClick="l.verifiCoord(username,pwd);"></button></row> </rows> </grid> </window>
in the console i get these errors;
Driver classe non trouveeeeeeeeeee Connection impossibleeeeeeeeee base de donneesjava.sql.SQLException: No suitable driver 23 avr. 2010 16:20:02 org.zkoss.zk.ui.impl.UiEngineImpl handleError:1130 GRAVE: >>java.lang.NullPointerException >> at course.Login.verifiCoord(Login.java:42) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
I precise that i dont want to use a persistence tool like hibernate.
thank u for your help
Please check that the ojdbc14.jar is in your classpath. Second check this link (http://www.rgagnon.com/javadetails/java-0112.html)
HTH
thank u yamilbracho
i have already the ojdbc.jar.
as i said the connection works well when it is just in a class java. but when i do an interaction with a zul file it doesnt work. thats the problem
OK I think you will need to specify your static class a init class for ypur zul page.Check http://docs.zkoss.org/wiki/Developer_reference_The_ZK_User_Interface_Markup_Language_Processing_Instructions_The_init_Directive
or (a better idea) use a composer for your page
hello,
As i m new to zk studio,I have wriiten the following code and i wanted to display the data in label and text box,Can anyone help me,
<?page title="edit" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Edit Records" border="normal">
<label style="color:red" value="EDIT" width="250px"/>
<tabbox>
<tabs>
<tab label="Home" closable="true"/>
<tab label="Edit Record" closable="true"/>
</tabs>
</tabbox>
<grid>
<columns>
<column label="Type" width="150px" />
<column label="Content" />
</columns>
<rows>
<row>
<label value="Name" width="150px" />
<textbox value="" width="150px" id="name"/>
</row>
<row>
Phone:
<textbox value="" width="150px" id="phone"/>
</row>
<row>
Address
<vlayout>
<textbox width="250px" value="" id="address"/>
<hlayout>
<label value="Zip code :" />
<textbox value="" width="150px" id="zip"/>
</hlayout>
</vlayout>
</row>
</rows>
</grid>
<button label="Show Records" onClick="show_rec()" />
<zscript language="Java">
{
import java.sql.*;
import javax.sql.*;
import com.mysql.jdbc.Driver.*;
import java.util.*;
import java.lang.*;
public void show_rec()
{
Connection conn = null;
try
{
String userName = "root";
String password = "123456";
String url = "jdbc:mysql://localhost:3306/telephone_directory";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url,userName,password);
Statement s = conn.createStatement();
s.executeQuery ("SELECT * FROM test WHERE phone="";");
ResultSet rs = s.getResultSet ();
int count = 0;
while (rs.next ())
{
String nameValue = name.getValue();
String phoneValue = phone.getValue();
String addressValue = address.getValue();
String zipValue = zip.getValue();
++count;
}
s.close();
rs.close();
}
catch (Exception e)
{
System.err.println ("ERROR: "+ e.getMessage());
}
finally
{
if (conn != null)
{
try {
conn.close ();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println ("Database connection terminated");
}
}
}
}
</zscript>
</window>
</zk>
thanks,
swati123, please open a new dedicated topic in Help forum and use the tags to better include your code chunks...
BTW, you have to iterate over your ResultSet and put items in a list, in order to iterate over it and render your grid... see the documentation, plenty of examples.
hello all,
please rectify my code,i wanted to display the data in grid view. I dont know much about grid.
So please can any one explain me the what row renderer,list model ,gruop model etc. how to write the code about grid view.
please check the following code .
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Search" border="normal" maximized="false" >
<label value="Enter your Name" /><textbox value="" width="250px" id="name"/>
<label style="color:green" value="OR" width="100px"/>
<label value="Enter your phone no" /><textbox value="" width="250px" id="phone"/>
<button label="Search" onClick="show_rec()" id="btn1"/>
<grid>
<columns>
<column label="Name"/>
<column label="Phone"/>
<column label="Adress"/>
<column label="zip"/>
</columns>
<rows>
<row>
</row>
</rows>
</grid>
<zscript language="JAVA" >
{
import java.sql.*;
import javax.sql.*;
import com.mysql.jdbc.Driver.*;
import java.util.*;
import java.lang.*;
public void show_rec()
{
Connection conn = null;
try
{
String userName = "root";
String password = "123456";
String url = "jdbc:mysql://localhost:3306/telephone_directory";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url,userName,password);
Statement s = conn.createStatement();
s.executeQuery ("SELECT * FROM test where name='"+name.Value+"' OR phone='"+phone.Value+"'");
ResultSet rs = s.getResultSet ();
int count = 0;
while (rs.next ())
{
String nameValue = ((Textbox)getFellow("nameValue")).getValue();
++count;
}
s.close();
rs.close();
}
catch (Exception e)
{
System.err.println ("ERROR: "+ e.getMessage());
}
finally
{
if (conn != null)
{
try {
conn.close ();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println ("Database connection terminated");
}
}
}
}
</zscript>
</window>
</zk>
hello all,
Can anyone explain me with simple example how to display the data in a grid from database.?
There are so many big examples in zk sandbox,that they are confusing me???
So ,please explain me using one text box and button,
thanks,
hi..
when I am adding a constraint in text field,it is throwing an error.pls rectify my code.I am unable to find out the bug.<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Name And Phone Numbers" border="none" width="600px" height="600px">
<menubar style="float:right;" height="27px">
<menuitem label="Edit Records" href="/edit.zul" />
</menubar>
<grid>
<columns visible="true">
<column label="Name and phone number" style="font-weight:bold,font-size:35px;color:blue" height="25px" width="175px" />
</columns>
</grid>
<grid>
<columns visible="true">
<column label="Type" width="300px" />
<column label="Content" />
</columns>
<rows>
<row>
<label value="Name*" width="150px" />
<textbox value="" width="150px" id="name" constraint="no empty , /*/ : Enter name "/>
</row>
<row spans="2"></row>
<row>
Phone*:
<textbox value="" width="150px" id="phone" maxlength="10" />
</row>
<row>
Address*:
<vlayout>
<textbox width="250px" value="" id="address" />
<hlayout>
<label value="Zip code*:" />
<textbox value="" width="150px" id="zip" maxlength="6" />
</hlayout>
</vlayout>
</row>
</rows>
</grid>
<button label="Submit" width="150px" onClick="submit()"/>
<zscript language="Java">
{
import java.sql.*;
import javax.sql.*;
import com.mysql.jdbc.Driver.*;
import java.util.*;
import java.lang.*;
public void submit()
{
Connection conn = null;
String userName = "root";
String password = "123456";
String url = "jdbc:mysql://localhost:3306/telephone_directory";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url,userName,password);
System.out.println ("Database connection established");
PreparedStatement ps=conn.prepareStatement("INSERT INTO test VALUES(?,?,?,?);");
{
try
{
ps.setString(1,name.Value);
ps.setString(2,phone.Value);
ps.setString(3,address.Value);
ps.setString(4,zip.Value);
ps.executeUpdate();
name.setValue("");
phone.setValue("");
address.setValue("");
zip.setValue("");
ps.close ();
}
catch (Exception e)
{
System.err.println ("ERROR: "+ e.getMessage());
}
finally
{
if (conn != null)
{
conn.close ();
System.out.println ("Database connection terminated");
}
}
}
}
}
</zscript>
</window>
</zk>
it gives the following error:
INFO: Source is changed: /name.zul
Database connection established
ERROR: Enter name
Database connection terminated
Asked: 2010-04-23 09:38:34 +0800
Seen: 1,511 times
Last updated: Nov 04 '14