3 Replies - 387 Views - Last Post: 07 March 2011 - 08:20 AM Rate Topic: -----

#1 therook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 09-September 09

input new items into two different tables, getting an error

Posted 05 March 2011 - 08:12 PM

Im supposed to be using a transcation to input new items into two different tables (sales and salesdetails). Im using the form to get the data to go into the table. It appears that my first statement is working correctly (string inone) but when I try and execute intwo i recieve the error "statusMsg=Error: For input string: ""<br>". Any help on where the problem is stemming from would be great. Thanks so much!

<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="java.sql.*" %>

<html>
<head>
    <link rel="stylesheet" href="style.css" type="text/css" media="screen">

    <title>Hello</title>
</head>
<center>
    <h1>Hello</h1>

    <form name="input" action="" method="get">
        <h4>Input Information For Entire Order</h4>
        <label for="sonum">Sales Number:</label> <input type="text" name="sonum" id="sonum"/><br/>
        <label for="stor_id">Store ID:</label> <input type="text" name="stor_id" id="stor_id"/><br/>
        <label for="ponum">Purchase Number:</label><input type="text" name="ponum" id="ponum"/><br/>
        <label for="sdate">Sales Date:</label><input type="text" name="sdate" id="sdate"/><br/>

        <h4>Input Information For Detail Items</h4>
        <h5>Detail Item One</h5>
        <label for="sonum2">Sales Number:</label> <input type="text" name="sonum" id="sonum2"/><br/>
        <label for="title">Title: </label><input type="text" name="title_id" id="title"/><br/>
        <label for="qty_ordered">Quantity Ordered: </label><input type="text" name="qty_ordered" id="qty_ordered"><br/>
        <label for="qty_shipped">Quantity Shipped: </label><input type="text" name="qty_shipped" id="qty_shipped"><br/>
        <label for="date_shipped">Shipped Date: </label><input type="text" name="date_shipped" id="date_shipped"><br/>
        
        <input type="submit" value="Submit"/>
    </form>
    <%
        String statusMsg = "";
        boolean debug = true;
        Connection con = null;
        Statement stmnt = null;



        
        Enumeration keys = request.getParameterNames();
        Hashtable<String, String> parms = new Hashtable<String, String>();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String value = request.getParameter(key);
            if (debug) System.out.println(String.format("key=%s value=%s", key, value));
            parms.put(key, value);
        }


        try {
            
            Class.forName("org.postgresql.Driver");

            
            con = DriverManager.getConnection("jdbc:postgresql://localhost/blah", "blah", "password");

            
            con.setAutoCommit(false);

         
            stmnt = con.createStatement();
            stmnt = con.createStatement();
            
           

            String inone = ("INSERT INTO sales VALUES ('" + Integer.parseInt(parms.get("sonum")) + "','" + parms.get("stor_id") + "','" + parms.get("ponum") + "') ");
            String intwo = ("INSERT INTO salesdetails VALUES ('" + Integer.parseInt(parms.get("sonum")) + "','" + Integer.parseInt(parms.get("qty_ordered")) + "','" + Integer.parseInt(parms.get("qty_shipped")) + "','" + parms.get("title_id") + "','" + parms.get("date_shipped") + "') ");


            stmnt.execute(inone);
            stmnt.execute(intwo);

            con.commit();
            con.close();


        } catch (Exception e) {
            statusMsg += String.format("Error: %s<br>", e.getMessage());
            con.rollback();
            con.close();

        } finally {
        }
        if (debug) System.out.println("statusMsg=" + statusMsg);

    %>
    <p><%= statusMsg%>
    </p>
</center>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: input new items into two different tables, getting an error

#2 no2pencil  Icon User is offline

  • Dic Head
  • member icon

Reputation: 5163
  • View blog
  • Posts: 26,837
  • Joined: 10-May 07

Re: input new items into two different tables, getting an error

Posted 05 March 2011 - 08:24 PM

** Renamed title to be more descriptive **
Was This Post Helpful? 0
  • +
  • -

#3 therook  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 09-September 09

Re: input new items into two different tables, getting an error

Posted 05 March 2011 - 08:33 PM

View Postno2pencil, on 05 March 2011 - 08:24 PM, said:

** Renamed title to be more descriptive **

Sorry about that and thanks.
Was This Post Helpful? 0
  • +
  • -

#4 rgfirefly24  Icon User is online

  • D.I.C Lover
  • member icon


Reputation: 262
  • View blog
  • Posts: 1,460
  • Joined: 07-April 08

Re: input new items into two different tables, getting an error

Posted 07 March 2011 - 08:20 AM

It appears that you have a double quote in your string somewhere that is prematurely ending your string. do you have a way of stepping through the code and showing the values of each of your query items in parms? with the information you've given there is no way to understand exactly what is causing your error.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1