0

How to connect oracle zul file and java file

asked 2010-04-23 09:38:34 +0800

fatimatall gravatar image fatimatall
6 1

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

delete flag offensive retag edit

15 Replies

Sort by ยป oldest newest

answered 2014-11-04 16:58:03 +0800

sandralambert gravatar image sandralambert
1
http://www.pottytraininga...

updated 2014-11-04 16:58:35 +0800

Did you put the driver under WEB-INF/lib too? I guess that's the reason you can't find the driver in Servlet.


http://pottytraininganswers.com (Potty Training) | http://pottytraininganswers.com/potty-training-101.html (Potty Training Tips) | http://pottytraininganswers.com/potty-training-girls.html (Potty Training Girls) | http://pottytraininganswers.com/potty-training-boys.html (Potty Training Boys) |

link publish delete flag offensive edit

answered 2014-11-03 07:28:26 +0800

wipekk gravatar image wipekk
1
http://www.rzadzapieniadz...

THANKS works really well!

link publish delete flag offensive edit

answered 2014-11-02 22:43:44 +0800

Darksu gravatar image Darksu
1991 1 4

Hello fatimatall, nirmalsri, and wiles,

You have to place the driver under the path /WebContent/WEB-INF/lib

Please find at the folllowing url an associated example:

http://books.zkoss.org/wiki/ZKDeveloper'sReference/Integration/Persistence_Layer/JDBC

Best Regards,

Darksu

link publish delete flag offensive edit

answered 2014-10-28 14:16:47 +0800

wiles gravatar image wiles
1
http://www.celoszczedzani...

i had similiar problem :/

link publish delete flag offensive edit

answered 2014-10-28 12:09:43 +0800

nirmalsri gravatar image nirmalsri
1

hai friends i am facing class not found exception. com.mysql.jdbc.Driver

already i have configure mysql driver but repeated same error.

link publish delete flag offensive edit

answered 2012-06-04 07:30:38 +0800

swati123 gravatar image swati123
66

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

link publish delete flag offensive edit

answered 2012-05-23 09:06:26 +0800

swati123 gravatar image swati123
66

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,

link publish delete flag offensive edit

answered 2012-05-18 06:58:45 +0800

swati123 gravatar image swati123
66

pls help me for my previous post.I need it urgently.

link publish delete flag offensive edit

answered 2012-05-17 10:52:18 +0800

swati123 gravatar image swati123
66

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>

link publish delete flag offensive edit

answered 2012-05-15 15:19:26 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

updated 2012-05-15 15:21:17 +0800

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.

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: 2010-04-23 09:38:34 +0800

Seen: 1,511 times

Last updated: Nov 04 '14

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