Results 1 to 3 of 3

Thread: Java-JSP

  1. #1
    techsing14 is offline Member
    Join Date
    Oct 2010
    Posts
    24
    Rep Power
    0

    Default Java-JSP

    Hi

    I need help to insert IP Address, Subnet Mask values into MS Access database dynamically from jsp page(ex, IP: 10.161.133.224, Subnet Mask: 255.255.255.240). This is my code:

    additemtodatabase.jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ page language="java" import="java.sql.*"%>
    <html>
    <body bgcolor="white">
    <body>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <title> Create Page </title>
    <h1 align="Center">Welcome to Create Item Page</h1>
    <form action="additemtodatabase.jsp" method="post">
    <br><br><br>
    <TABLE align="center" width="300px" style="background-color:#EDF6EA;border:1px solid #000000;">
    <tr><td colspan=2 style="font-weight:bold;" align="center">Create Item</td></tr>
    <tr><td colspan=2 align="center" height="10px"></td></tr>
    <tr>
    <td style="font-weight:bold;">IP Address</td>
    <td><input type="numeric" name="IPAddress" value="" size="20"></td>
    </tr>
    <tr>
    <td style="font-weight:bold;">Subnet Mask</td>
    <td><input type="numeric" name="Subnetmask" value="" size="20"></td>
    </tr>
    <tr>
    <td style="font-weight:bold;">VLAN ID</td>
    <td><input type="numeric" name="VLANID" value="" size="20"></td>
    </tr>
    <tr>
    <td style="font-weight:bold;">Allocated Hostname</td>
    <td><input type="text" name="AllocatedHostname" value="" size="20"></td>
    </tr>
    <tr>
    <td style="font-weight:bold;">Aggregated Switch</td>
    <td><input type="text" name="AggregatedSwitch" value="" size="20"></td>
    </tr>
    <tr>
    <td style="font-weight:bold;">Headend Name</td>
    <td><input type="text" name="HeadedName" value="" size="20"></td>
    </tr>
    <tr>
    <td style="font-weight:bold;">Date Issued</td>
    <td><input type="text" name="DateIssued" value="" size="20"></td>
    </tr>
    <tr>
    <td style="font-weight:bold;">Remarks</td>
    <td><input type="text" name="Remarks" value="" size="20"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="Submit" value="Save" style="background-color:#49743D;font-weight:bold;color:#ffffff;"></td>
    </tr>
    <tr><td colspan=2 align="center" height="10px"></td></tr>
    </TABLE>
    <%
    String IPAddress = request.getParameter("IPAddress");
    String SubnetMask = request.getParameter("SubnetMask");
    String VLANID = request.getParameter("VLANID");
    String AllocatedHostname = request.getParameter("AllocatedHostname");
    String AggregatedSwitch = request.getParameter("AggregatedSwitch");
    String HeadendName = request.getParameter("HeadendName");
    String DateIssued = request.getParameter("DateIssued");
    String Remarks = request.getParameter("Remarks");

    String connectionURL = "jdbc:odbc:Databaseipadd";
    Connection connection = null;
    PreparedStatement pstatement = null;
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newI nstance();
    int updateQuery = 0;
    if (IPAddress != null && SubnetMask != null && VLANID != null && AllocatedHostname != null && AggregatedSwitch != null && HeadendName != null && DateIssued != null && Remarks != null) {
    if (IPAddress != "" && SubnetMask != "" && VLANID != "" && AllocatedHostname != "" && AggregatedSwitch != "" && HeadendName != "" && DateIssued != "" && Remarks != "") {
    try {
    connection = DriverManager.getConnection(connectionURL);
    String queryString = "INSERT INTO iptable (IPAddress,SubnetMask,VLANID,AllocatedHostname,Agg regatedSwitch,HeadendName,DateIssued,Remarks) VALUES (?, ?, ?, ? , ? , ? , ? , ? )";
    pstatement = connection.prepareStatement(queryString);
    pstatement.setString(1, IPAddress);
    pstatement.setString(2, SubnetMask);
    pstatement.setString(3, VLANID);
    pstatement.setString(4, AllocatedHostname);
    pstatement.setString(5, AggregatedSwitch);
    pstatement.setString(6, HeadendName);
    pstatement.setString(7, DateIssued);
    pstatement.setString(8, Remarks);
    pstatement.executeUpdate();
    %>

    <br>
    <TABLE style="background-color: #E3E4FA;"
    WIDTH="30%" border="1">
    <tr><th>Data is inserted successfully
    in database.</th></tr>
    </TABLE>

    <% } catch (Exception ex) {
    out.println("Unable to connect to database");
    out.println(ex.getMessage());
    } finally {
    pstatement.close();
    connection.close();
    }
    }
    }
    %>
    </form>
    </body>
    </html>


    This code is not working, its not inserting values, even giving an error, Please can anyone help me to solve this , its very very urgent.

    Reply with an answer ASAP.

    Thanks in advance
    Lissy.

  2. #2
    go4soumya is offline Member
    Join Date
    Oct 2010
    Posts
    32
    Rep Power
    0

    Default

    paste the error code...i think u'r having issues with database connectivity!

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default

    And that db code should never be in a JSP page like that...how do you expect to be able to debug it to ensure it's working?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •