Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JavaScript not working as intended

User_H95GNApr 2 2017 — edited Apr 3 2017

OS: Windows 10

Java netbeans IDE 8.2

derby database

I am trying to write a JavaScript function that calculates the avg for all shipping cost. But when I run my code I can't match what I have in JavaScript to what i have in my database:And while my code runs successfully it is not doing what i intended it to do.

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<%@ page language="java" import="java.util.*" errorPage="" %>

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

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>prder</title>

<script type="text/javascript">

/* <![CDATA[ */

public class actor {

   

   

    String method = "";

            method = request.getMethod();

            if (method.equalsIgnoreCase("POST")) {

                String ord_id = request.getParameter("ord_id");

                String shippingcost = request.getParameter("shippingcost");

                String unitprice = request.getParameter("unitprice");

                Connection aConnection = null;

                try {

                    String driver = "org.apache.derby.jdbc.ClientDataSource";

                    Class.forName(driver);

                    // Setup the connection with the DB

                    String url = "jdbc:derby://localhost:1527/Certificate;user=app;password=password";

                    aConnection = DriverManager.getConnection(url);

                    aConnection.setAutoCommit(false);

                    System.out.println("DB Connection successful");

                    StringBuilder aBuilder = new StringBuilder();

                    aBuilder.append("INSERT INTO orderdetail(ord_id,shippingcost, unitprice)");

                    aBuilder.append("VALUES (?, ?, ?)");

                    String aPreparedQuery = aBuilder.toString();

                    PreparedStatement aStatement = aConnection.prepareStatement(aPreparedQuery);

                    aStatement.setString(1, ord_id);

                    aStatement.setString(2, shippingcost);

                    aStatement.setString(3, unitprice);

                    aStatement.executeUpdate();

                    aConnection.commit();

                } catch (Exception e) {

                    e.printStackTrace();

                    try {

                        aConnection.rollback();

                    } catch (Exception re) {

                        re.printStackTrace();

                    }

                } finally {

                    // try to close the connection...

                    try {

                        // close the connection...

                        aConnection.close();

                    } catch (Exception e) {

                        e.printStackTrace();

                    }

                }

            }

   

}

    var unitprice=[];

    var shippingcost=[];

    var total=price+shipping;

    function calculateShipping(){

    if (price <= 25){

    shipping = (price + 1.5);

    }

    else {

    shippingcost = (price * 10 / 100);

    }

}

/* ]]> */

</script>

</head>

<body>

<form name ="calculate" action="" >

<p>Enter Purchase Price</p>

<input type="text" name="ent" >

<input type="button" name="button" value="Submit" onClick="calculateShipping()" />

</form>

</body>

</html>

Comments

vermio
Answer

The isssue was solved by Oracle Support

Marked as Answer by vermio · Sep 27 2020
1 - 1

Post Details

Added on Apr 2 2017
1 comment
289 views