after I insert an article, the database is empthy....

Discussions

EJB programming & troubleshooting: after I insert an article, the database is empthy....

  1. after I insert an article, the database is empthy.... I don't understand why it was working at until I decide to add another field. I have 3 files which they are submitart.jsp <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include file ="connection.jsp" %> Submit Article <!-- body { background-color: #FFFFFF; } .menu-text { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 17px; } .link-text {font-size: 13px} .search-box { border: 1px solid #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #333333; background-color: #FFFFFF; } body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; } .style1 {color: #FFFFFF} a:link { color: #333333; text-decoration: none; } a:visited { text-decoration: none; color: #333333; } a:hover { text-decoration: none; color: #333333; } a:active { text-decoration: none; color: #333333; } --> <!-- ImageReady Slices (Untitled-1) -->
    [Home] [Contact Us] [About Us] [RSS]


    Article Title Author Name Article Description: Article Text: Select Category: <% PreparedStatement statement = con.prepareStatement("select Category_Name from category"); ResultSet resSet = statement.executeQuery(); while(resSet.next()){ String cat = resSet.getString("Category_Name"); %> <%=cat%> <% } %>

    Design Created By DansTuts.com <!-- End ImageReady Slices -->
    Design downloaded from free website templates.
    the next file is submitaction.jsp <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include file ="connection.jsp" %> <%@ include file ="validate.jsp" %> <% //Get Category_Name PreparedStatement statement; //insert article when all the fields are fill it up if (paramProd){ //insert the new article here try{ statement = con.prepareStatement("insert into articles (Category_Name, article_title, article_desc, User_ID, Article_text,) values(?,?,?,?,?)"); statement.setString(1,Category_Name); statement.setString(2,article_title); statement.setString(3,article_desc); statement.setString(4,User_ID); statement.setString(5,Article_text); statement.executeUpdate(); }catch(Exception e){ System.out.println("here i am"); e.printStackTrace(); } /** Item Insert it **/ } %> Process Submit Article <!-- body { background-color: #FFFFFF; } .menu-text { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 17px; } .link-text {font-size: 13px} .search-box { border: 1px solid #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; color: #333333; background-color: #FFFFFF; } body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; } .style1 {color: #FFFFFF} a:link { color: #333333; text-decoration: none; } a:visited { text-decoration: none; color: #333333; } a:hover { text-decoration: none; color: #333333; } a:active { text-decoration: none; color: #333333; } --> <!-- ImageReady Slices (Untitled-1) -->
    [Home] [Contact Us] [About Us] [RSS]


     

    <!-- Display the last article inserted OK --> <% if (paramProd){ %>

    The article was inserted in the database OK

    <%} else { %>

    Please try again

    <%} %> <% con.close();%>

    Design Created By DansTuts.com <!-- End ImageReady Slices -->
    Design downloaded from free website templates.
    and the last one is validate.jsp <% int article_id = 0; String Category_Name = null; String article_title = null; String article_desc = null; String User_ID = null; String Article_text = null; try { article_id = 0; Category_Name = request.getParameter("Category_Name"); article_title = request.getParameter("article_title"); article_desc = request.getParameter("article_desc"); User_ID = request.getParameter("User_ID"); Article_text = request.getParameter("Article_text"); System.out.println("lll here ==== "+Category_Name); } catch(Exception e) { e.printStackTrace(); } // assume invalid boolean paramProd = false; if (article_title != null ) { // setvalid paramProd = true; } %> can any one help me here pls..........
  2. Hi there. See this line: statement = con.prepareStatement("insert into articles (Category_Name, article_title, article_desc, User_ID, Article_text,) values(?,?,?,?,?)"); There is a comma too much in your insert statement. May be that's the problem? It should cause an exception with a strict SQL parser, because the engine expects another column. Just a guess. Have fun.