Database question

HiI need to create a textfield validator that checks that the input doesn't exist in the database. Is there an easy way to achieve this?Thanx--Haim
[190 byte] By [babysnakes] at [2007-11-26 9:10:22]
# 1

Check out these:

Adding your own Validation Handler tutorial:

http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/cus tomvalidator.html

And then you could have a cachedrowset with your query to send in the value as parameter and check, if it exists in the database.

If you want to do the JDBC way ...

http://blogs.sun.com/roller/page/jfbrown/20051116

HTH,

Sakthi

sakthivelgopal at 2007-7-6 23:29:12 > top of Java-index,Development Tools,Java Tools...
# 2
> If you want to do the JDBC way ...> http://blogs.sun.com/roller/page/jfbrown/20051116Actually that's the way I solved this. it seemed to be the simplest (maybe because I don't really know how to handle CachedRowSet efficiently yet...).Thanks
babysnakes at 2007-7-6 23:29:12 > top of Java-index,Development Tools,Java Tools...
# 3

The Login page in the adventure builder sample application does something like what you want. Here is an excerpt from the source

getSessionBean1().getSignonRowSet().setObject(1,(String)getNewUsernameTextField().getText());

signonDataProvider.refresh();

if (signonDataProvider.getRowCount() > 0) {

error("This name is already used. Try a different name.");

return null;

}

Also, here is an AJAX way to do it (JavaOne LAB-5655Building AJAX-Based JavaServer Faces Web Applications With Sun Java Studio Creator):

http://www.javapassion.com/handsonlabs/5655_ajaxcreator.zip

MrsJetsons at 2007-7-6 23:29:12 > top of Java-index,Development Tools,Java Tools...
# 4

> code]getSessionBean1().getSignonRowSet().setObject(1,(

> String)getNewUsernameTextField().getText());

>signonDataProvider.refresh();

>

> if (signonDataProvider.getRowCount()

> > 0) {

> error("This name is already used.

> Try a different name.");

>return null;

> code]

Great, that's what I was looking for.

>

> Also, here is an AJAX way to do it (JavaOne LAB-5655

> Building AJAX-Based JavaServer Faces Web

> Applications With Sun Java Studio Creator):

>

> http://www.javapassion.com/handsonlabs/5655_ajaxcreato

> r.zip

I'll take a look at it also.

Thanks

--

Haim

babysnakes at 2007-7-6 23:29:12 > top of Java-index,Development Tools,Java Tools...