ecllips tomcat7 mysql jsp を使ってプログラミングをしている
初心者です。
コードの165行目にsqlの構文エラーのようなものが発生していて
実行はできるんですがエクリプスの例外エラーの画面に飛んでしまいます。
経験者の方、ご指摘いただけますか。
###前提・実現したいこと
ここに質問したいことを詳細に書いてください
(例)PHP(CakePHP)で●●なシステムを作っています。
■■な機能を実装中に以下のエラーメッセージが発生しました。
###発生している問題・エラーメッセージ
例外レポート メッセージ An exception occurred processing JSP page /index.jsp at line 156 153: Statement st2=conn2.createStatement(); 154: //HTMLから入力された、商品ID、単価、購入量、割引値をインサート 155: String sql2 = "INSERT INTO product(product_id,product_tanka,product_quantity,product_discount) VALUES("+productID+","+price2+","+quantity2+","+disCount+")"; 156: st2.execute(sql2); 157: st2.close(); 158: conn2.close(); 159: %> 原因 javax.servlet.ServletException: 原因 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have ###該当のソースコード ```jsp <%@ page contentType="text/html; charset=utf-8" import="java.sql.*" %> <!doctype html> <html> <head> <meta charset="utf-8"> <style> div#main{ margin: 50px; padding: 0; border: 5px solid black; height: 500px; width: 540px; } div#button{ margin: 5px 10px 10px 290px; border: 5px solid black; height: 480px; width: 230px; } div.list{ margin: -500px 10px 5px 5px; border: 5px solid black; height: 250px; width: 270px; overflow-y: scroll; } table.list{ height: 250px; width: 245px; } th{ height: 20px; } input{ width:50px; } div.output{ margin: 1px 10px 5px 5px; padding: 0; border: 5px solid black; height: 215px; width: 270px; overflow-y:scroll; } table.output{ height: 215px; width: 252px; } tr{ height: 5px; } a{ margin: 0 50px; padding: 0; } input.output{ height: auto; width: 75px; } td{ width:70px; } </style> </head> <body> <script type="text/javascript"> function showClock1() { var nowTime = new Date(); var nowMonth = nowTime.getMonth(); var nowDate = nowTime.getDate(); var nowHour = nowTime.getHours(); var nowMin = nowTime.getMinutes(); var nowSec = nowTime.getSeconds(); var msg = nowHour + ":" + nowMin + ":" + nowSec ; document.getElementById("time").innerHTML = msg; } setInterval('showClock1()',1000); </script> <form method="post" action="index.jsp"> <select name="product" > <option value="T">Tシャツ</option> <option value="S">パンツ</option> <option value="B">ボトム</option> <option value="J">ジャケット</option> </select> <select name="product" > <option value="10">10%</option> <option value="30">30%</option> <option value="50">50%</option> <option value="70">70%</option> </select> <input type="text" value="" name="quantity"> <input type="submit" value="登録"> </form> <div id="main"> <div id="button"></div> <div class="list"> <% int i=0; //添え字 String quantity=""; String product=""; String disCount=""; if(i==1){ quantity = request.getParameter("quantity");//htmlからの購入量の受け取り product = request.getParameter("product"); //htmlからの商品名の受け取り disCount = request.getParameter("discount");//htmlからの割引率の受け取り } i++; int price2=0; //単価 String productID=""; //商品ID int disCount2=0; //割引率 int quantity2=0; //量 //割引変数を判断して整数型に変換 if(disCount.equals("10")){ disCount2 = 10; }else if(disCount.equals("30")){ disCount2 = 30; }else if(disCount.equals("50")){ disCount2 = 50; }else if(disCount.equals("70")){ disCount2 = 70; } //購入量の受け取り if(quantity.equals("1")){ quantity2 = 1; }else if(quantity.equals("2")){ quantity2 = 2; }else if(quantity.equals("3")){ quantity2 = 3; }else if(quantity.equals("4")){ quantity2 = 4; } //商品名から判断し商品IDと単価を整数型変数に代入 if(product.equals("T")){ price2 = 1000; productID = "0001"; }else if(product.equals("S")){ price2 = 2000; productID = "0002"; }else if(product.equals("B")){ price2 = 3000; productID = "0003"; }else if(product.equals("J")){ price2 = 4000; productID = "0004"; } //データベースを開いてコネクション確立 Class.forName("com.mysql.jdbc.Driver"); Connection conn2=DriverManager.getConnection("jdbc:mysql://localhost/test?" ,"root","admin"); Statement st2=conn2.createStatement(); //HTMLから入力された、商品ID、単価、購入量、割引値をインサート String sql2 = "INSERT INTO product(product_id,product_tanka,product_quantity,product_discount) VALUES("+productID+","+price2+","+quantity2+","+disCount+")"; st2.execute(sql2); st2.close(); conn2.close(); %> <table border="1"> <% //データベースを開いてコネクション確立 Class.forName("com.mysql.jdbc.Driver"); Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/test?" ,"root","admin"); Statement st=conn.createStatement(); ResultSet res = st2.executeQuery("select * from product"); //データベースからの表示 while(res.next()){ out.println("<tr>"); out.println("<td>" + res.getString("product_id") + "</td>"); out.println("<td>" + res.getString("product_tanka") + "</td>"); out.println("<td>" + res.getString("product_quantity") + "</td>"); out.println("<td>" + res.getString("product_discount") + "</td>"); out.println("</tr>"); } //データベース閉じる st.close(); conn.close(); %> </table> </div> <div class="output"> <table border="1" class="output"> <tr><td colspan="5"><a id="time"></a></td><td>クレジット</td></tr> <tr><td colspan="5" id="shokei">小計</td><td><input type="text" value="" class="output"></td></tr> <tr><td colspan="5">お預かり</td><td>リボ</td></tr> <tr><td colspan="5">合計</td><td><input type="text" value="" class="output"></td></tr> <tr><td colspan="5">おつり</td><td>担当</td></tr> <tr><td colspan="5">会員コード</td><td></td></tr> <tr><td colspan="6">有効ポイント</td></tr> <tr><td colspan="6">伝票番号</td></tr> </table> </div> </div> <button type="button" onclick="shokei()">小計</button> </body> </html>
###試したこと
データベースの項目名が間違っていないかの照らし合わせ
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー