aspose file tools*
The moose likes JDBC and the fly likes mysql & incomplete insertions! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "mysql & incomplete insertions!" Watch "mysql & incomplete insertions!" New topic
Author

mysql & incomplete insertions!

Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
While working on a cattle drive assignment, I've encountered this phenomenon: When inserting a row of data into my table from a html form, two of the fields do not show up at all. I'm not sure why these two fields aren't showing up because from what I can see, I'm handling the code for all 6 fields in each row the same way. The boxes don't even show up, just void space. Going back to mysql, the new entries are included when I type: select * from tablename; and they are included when I ask for a count(*) of entries in the table, but they are not included if I do a query like so: select * from tablename where title = 'Whatever' ; An empty set is returned, or only complete records that meet the criteria will be included in the result set. The complete records are rows I added from within the mysql dos window. The records added from the html form are missing two of the fields, so they are incomplete. Why would they show up for some commands, and be invisible for others? I can't even delete these rows, because delete seems to be one of the commands that can't find them! Any ideas?
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
hhmm.. is it possible for us to see some code snippets of what you've done.. I think it'd be a bit helpful .
cheers


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Okay, code snippets it is!
"<input type=checkbox name=xxx value=Y>XXX\n"
"<input type=checkbox name=yyy value=Y>YYY\n\n"
the text fields and radio buttons in this same form are declared the same way and they work fine. The records are inserted as expected. The variables are declared like this:
String xxx = parms.getString( "xxx" ) ;
if( xxx == null )
{
xxx = "N" ;
}
String yyy = parms.getString( "yyy" ) ;
if( yyy == null )
{
yyy = "N" ;
}
The sql insert statement like so:

statement.executeQuery( "INSERT INTO TABLE ( AAA , BBB , CCC , XXX , YYY , DDD ) VALUES ( ' " + aaa + " ' , ' " + bbb + " ' , ' " + ccc + " ' , ' " + xxx + " ' , ' " + yyy + " ' , ' " + ddd + " ' )" ) ;
Fields AAA, BBB, CCC, DDD work when the record is inserted, but XXX and YYY don't work. Fields AAA, BBB, and DDD are text fields, and CCC is radio buttons. The only difference I can see is that XXX and YYY are checkboxes. What's going on here?
Wayne Turner
Greenhorn

Joined: Jul 18, 2002
Posts: 12
It looks like you are checking to see if the check boxes xxx and yyy are null, which would represent NO. But, what if they are YES? Looking at your code, it seems that if someone had checked them, the SQL statement would try to insert a NULL into the table, which wouldn't work. The table is expecting either zero (NO) or 1 (YES).
My suggestion is to test xxx and yyy a bit more. In addition to testing them for NULL, try testing them for zero and one. If they are NULL, put in the value zero (0). And why test for zero? Well, someone could have checked it (1) then changed their mind and unchecked it (0).
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
For the assignment I'm working on, the value returned by the checkbox should be Y for checked and N for unchecked. If the box is checked, value=Y, so if unchecked, I need the value to be "N". If I just print the value returned on a line, I get Y or null, depending. What I can't figure out is why the Y or N isn't being inserted into my table data. Is it perhaps because checkboxes return a number and not a Character value?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mysql & incomplete insertions!