Forum Stats

  • 3,752,912 Users
  • 2,250,585 Discussions
  • 7,868,049 Comments

Discussions

JavaScript not working as intended

User_H95GN
User_H95GN Member Posts: 409 Bronze Badge
edited Apr 3, 2017 10:31AM in NetBeans

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>

Answers

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,492 Red Diamond
    edited Apr 2, 2017 12:02PM

    User, you are posting in the wrong space. Your question has nothing to do with JDeveloper or ADF. Please post your question in a forum dedicated for the product you are using. May be ?

    Timo