• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic