Hov den kører nu:
<%@page
import="jsp.*"
import="java.sql.*"
%>
<%@ page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Insert title here</title>
</head>
<body>
<%
Connection c = MySQL.connect();
out.print(c);
MySQL.close(c);
%>
<%
String user_id = request.getParameter("user_id");
String user_email = request.getParameter("user_email");
String user_password = request.getParameter("user_password");
String connectionURL = "jdbc:
mysql://localhost:3306/shop"; Connection connection = null;
PreparedStatement pstatement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
if(user_id != null && user_email != null && user_password != null) {
if(user_id != "" && user_email != "" && user_password != "") {
try {
connection.DriverManager.getConnection(connectionURL, "root", "");
String queryString = "INSERT INTO info (user_id, user_email, user_password) VALUES(?, ?, ?)";
pstatement = connection.prepareStatement(queyString);
pstatement.setString(1, user_id);
pstatement.setString(2, user_email);
pstatement.setString(3, user_password);
updateQuery = pstatement.executeUpdate();
%>
<br>
<table>
<tr>
<th>Data was inserted successfully</th>
</tr>
</table>
<%
}catch(Exception ex) {
out.println("Unable to connect to database");
}
finally {
pstatement.close();
connection.close();
}
}
}
%>
<br><br><br>
<form method="post" action="index.jsp">
<table>
<tr>
<td>UserID</td><td><input type="text" name="user_id"></td>
</tr>
<tr>
<td>Email</td><td><input type="text" name="user_email"></td>
</tr>
<tr>
<td>Password</td><td><input type="text" name="user_password"></td>
</tr>
</table>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>
Når jeg prøver at indtaste noget i min formel, får jeg dog denne besked:
HTTP Status 500 - Unable to compile class for JSP:
type Exception report
message Unable to compile class for JSP:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 34 in the jsp file: /index.jsp
DriverManager cannot be resolved or is not a field
31: if(user_id != null && user_email != null && user_password != null) {
32: if(user_id != "" && user_email != "" && user_password != "") {
33: try {
34: connection.DriverManager.getConnection(connectionURL, "root", "");
35: String queryString = "INSERT INTO info (user_id, user_email, user_password) VALUES(?, ?, ?)";
36:
37: pstatement = connection.prepareStatement(queyString);
An error occurred at line: 37 in the jsp file: /index.jsp
queyString cannot be resolved to a variable
34: connection.DriverManager.getConnection(connectionURL, "root", "");
35: String queryString = "INSERT INTO info (user_id, user_email, user_password) VALUES(?, ?, ?)";
36:
37: pstatement = connection.prepareStatement(queyString);
38:
39: pstatement.setString(1, user_id);
40: pstatement.setString(2, user_email);
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728
Nogle der kan læse noget udfra det? :-/