• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
peter moss
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic