我错在这里如何纠正这个
String Sql="select * from login where username='"+name+"' AND password='"+abc+"'";
c1.st.executeQuery(Sql);
{
out.println("aa");
}
catch(SQLException ex)
{
我在这里唯一错误这是jsp中的登录页面。我这里唯一错误的是这是jsp中的登录页面。
db conn.jsp
<%@page import="com.mysql.jdbc.Connection"%>
<%@page import="com.mysql.jdbc.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%@ page import ="java.sql.*" %>
<%
Connection c1 = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
c1 = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/teacher","root", "abcde");
}
catch (Exception cnfe) {
System.out.println("Couldn't find the driver!");
System.out.println("Couldn't connect: print out a stack trace and exit.");
System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
}
try {
st = (Statement) c1.createStatement();
System.out.println("Statement Created Successfully");
} catch (SQLException se) {
System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
se.printStackTrace();
}
if (c1 != null) {
System. out.println("Hooray! We connected to the database!");
} else {
System.out.println("We should never get here.");
}
%>
<%
try{
String name=request.getParameter("username");
String abc=request.getParameter("password");
String Sql="select * from login where username='"+name+"' AND password='"+abc+"'";
c1.st.executeQuery(Sql);
{ out.println("aa");
}
catch(SQLException ex)
{
out.println(ex);
}}
%>
错误:
HTTP Status 500 -
type Exception report
message
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: 60 in the jsp file: /db conn.jsp
c1.st cannot be resolved or is not a field
57:
58: String Sql="select * from login where username='"+name+"' AND password='"+abc+"'";
59:
60: c1.st.executeQuery(Sql);
61: {
62: out.println("aa");
An error occurred at line: 63 in the jsp file: /db conn.jsp
Syntax error, insert "}" to complete Block
60: c1.st.executeQuery(Sql);
61: {
62: out.println("aa");
63: }
64:
65: catch(SQLException ex)
66: `
答案 0 :(得分:1)
您有语法错误。请尝试使用以下语法。
org.json
答案 1 :(得分:1)
你忘了关闭街区。您有一个} 用于尝试,但没有一个用于关闭 out.println(“aa”):
try{
String name=request.getParameter("username");
String abc=request.getParameter("password");
String Sql="select * from login where username='"+name+"' AND password='"+abc+"'";
c1.st.executeQuery(Sql);
{ out.println("aa"); **}** -> you forgot this bracket
}
cat