質問内容
質問を評価する
(0ポイント)
|
eclipseを使用してのtomcatプロジェクトでJDBCへの接続がうまくいきません。
tomcat:ver6。 データベース:MySQL (usernameとpassは設定していません)
どなたか原因がわかる方がいましたら教えてください
_________________送信側jsp_________________________
<%@ page contentType="text/html; charset=Windows-31J" import="java.sql.*, javax.naming.*, javax.sql.*" %> <%! private String createOption(int start, int end){ StringBuffer builder = new StringBuffer(); for(int i=start;i<=end;i++){ builder.append("<option value='" + i + "'>" + i + "</option>"); } return builder.toString(); } %> <html> <head> <title></title> </head> <body> <h1 style="background:#cccccc">簡易データベース</h1> <form method="POST" action="send.jsp"> <table border="0"> <tr> <th align="right">顧客ID:</th> <td><input type="text" name="Customer_ID" size="50" maxlength="255" /></td> </tr> <tr> <th align="right">名前:</th> <td><input type="text" name="Customer_Name" size="50" maxlength="255" /></td> </tr> <tr> <th align="right">住所:</th> <td><input type="text" name="Customer_Address" size="50" maxlength="255" /></td> </tr> <tr> <th align="right">年齢:</th> <td><input type="text" name="Customer_age" size="70" maxlength="3" /></td> </tr> <tr> <td rowspan="2"> <input type="submit" value="登録" /> <input type="reset" value="クリア" /> </td> </tr> </table> </form> </body> </html>
__________________受信側jsp_______________________
<%@ page contentType="text/html; charset=Windows-31J" import="java.sql.*, javax.naming.*, javax.sql.*" %> <% request.setCharacterEncoding("Windows-31J");
//データベースに接続~ Context context = new InitialContext(); //パスの指定 java:comp/env/jdbcは定型文のため注意 DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/mydata"); Connection db = ds.getConnection(); //~データベース取得終了
//SQL文の指定 Customerテーブルの ID Name Address ageフィールドに値を入力する PreparedStatement ps = db.prepareStatement("INSERT INTO schedule(Customer_ID,Customer_Name,Customer_Address,Customer_age) VALUES(? ,? ,? ,?)"); //プレイスフォルダに値を引き渡し String型データとして設定 値はget.jspより受け取る ps.setString(1, request.getParameter("Customer_ID")); ps.setString(2, request.getParameter("Customer_Name")); ps.setString(3, request.getParameter("Customer_Address")); ps.setString(4, request.getParameter("Customer_age")); ps.executeUpdate(); ps.close(); db.close(); response.sendRedirect("get.jsp"); %>
<html> <head>
<title>Insert title here</title>
</head> <body>
</body> </html>
_____________________xml______________________
<?xml version="1.0" encoding="UTF-8" ?> <Context displayName="MyData JDBC" docBase="mydata" path="/web" reloadable="true"> <Resource name="jdbc/mydata" auth="Container" type="javax.sql.DataSource" username="" password="root" driverClassName="org.gjt.mm.mysql.Driver" url="jdbc:mysql://localhost/mydata?useUnicode=true&characterEncoding=Windows-31J" maxActive="4" maxWait="5000" maxIdle="2" validationQuery="SELECT count(*) FROM customer" /> </Context>
|