aspose file tools*
The moose likes JSP and the fly likes  can you help with this sql statement to insert checkbox data using JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark " can you help with this sql statement to insert checkbox data using JSP?" Watch " can you help with this sql statement to insert checkbox data using JSP?" New topic
Author

can you help with this sql statement to insert checkbox data using JSP?

peter moss
Greenhorn

Joined: Aug 22, 2003
Posts: 9
can you help with this sql statement to insert checkbox data using JSP?
I'm passing some checkbox data to a jsp page and I'm trying to insert this data into an access database. Here's the code:
-------------------------------------------
<%@ page import="java.sql.*" %>
<%
String accnum = request.getParameter("accnum");
String series = request.getParameter("series");
String query = "INSERT INTO Saved (AccessionID, SeriesFolder, ImageName) VALUES ";
Driver drv = (Driver)
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc dbc:RTF");
Statement stmt = conn.createStatement();
String insertimages[] = request.getParameterValues("selectedimages");
int len = insertimages.length;
if (len > 0) {
for (int i = 0; i < len; i++) {
query = query + "('" + accnum + "', " + "'" + series + "', " + "'" + insertimages[i] + "'), ";
}
query = query + "('9000000', 'nonsensefolder', 'nonsenseimg');";
stmt.executeUpdate(query);
stmt.close();
}
conn.close();
--------------------------------------------------
the url that the jsp page is receiving contains acccnum & series variables, as well as a few selected images variables from checkboxes.
when i try this sql statement as a test in a jsp paage with out the if / for loop it works fine:
String testquery = "INSERT INTO Saved (AccessionID, SeriesFolder, ImageName) VALUES " +
"('8888888', '8888888folderseries1', '8888888image01.png');";
so the problem is happens when I try to use the selectedimages data from the checkbox/url instead of just plugging in test numbers.
please help... i'm been stuck on this forever
thanks
toma lam
Greenhorn

Joined: Aug 25, 2003
Posts: 4
What kind of error are you getting?
I see a typo in the statement within the If statement, at the end you have a comma instead of a semi-colon.
Also, does the database allow null values? These variables may be empty and will return null values.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can you help with this sql statement to insert checkbox data using JSP?