大家,早安 !我创建了一个带有一些单选按钮的 jsp 页面。现在,我正在接收用户对 servlet 内的数组中的那些单选按钮的响应。现在我想将这些数组项发送到我的 oracle 数据库表中。但我遇到了问题。jsp页面的代码是:
<%@page import="java.util.Calendar"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="TestAms" method="post">
<%
Calendar cal = Calendar.getInstance();
int md = cal.getActualMaximum(Calendar.DATE);
for(int i = 0; i <= md; i++){
%>
<input type="radio" name="<%= i%>" value="<%=i %>">
<%
}
%>
<input type="submit" value="SUBMIT">
</form>
</body>
</html>
servlet 的代码是:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestAms extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
Connection conn = null;
PreparedStatement pstmt = null;
Calendar cal = Calendar.getInstance();
int md = cal.getActualMaximum(Calendar.DATE);
int count =0;
String s[] = new String[md+1];
String jan = "JAN";
String query;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","urja","urja");
for (int y=1; y<=md; y++){
s[y] = request.getParameter(Integer.toString(y));
out.println(s[y]);
if( y < md ){
int z = y+1;
out.println("db var : " + z);
query = "UPDATE V_TEST SET \"" + z + "\" = ? WHERE V_MONTH = '"+ jan +"'";
pstmt = conn.prepareStatement(query);
pstmt.setString(z, s[y]); //getting error in this line as per the debug report.
int i = pstmt.executeUpdate();
out.println("inserted : " + i);
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
finally {
if (conn != null) {
try {
conn.close();
pstmt.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
我的表 sql 是:
CREATE TABLE "V_TEST"
( "V_MONTH" VARCHAR2(4000) NOT NULL ENABLE,
"1" VARCHAR2(4000),
"2" VARCHAR2(4000),
"3" VARCHAR2(4000),
"4" VARCHAR2(4000),
"5" VARCHAR2(4000),
"6" VARCHAR2(4000),
"7" VARCHAR2(4000),
"8" VARCHAR2(4000),
"9" VARCHAR2(4000),
"10" VARCHAR2(4000),
"11" VARCHAR2(4000),
"12" VARCHAR2(4000),
"13" VARCHAR2(4000),
"14" VARCHAR2(4000),
"15" VARCHAR2(4000),
"16" VARCHAR2(4000),
"17" VARCHAR2(4000),
"18" VARCHAR2(4000),
"19" VARCHAR2(4000),
"20" VARCHAR2(4000),
"21" VARCHAR2(4000),
"22" VARCHAR2(4000),
"23" VARCHAR2(4000),
"24" VARCHAR2(4000),
"25" VARCHAR2(4000),
"26" VARCHAR2(4000),
"27" VARCHAR2(4000),
"28" VARCHAR2(4000),
"29" VARCHAR2(4000),
"30" VARCHAR2(4000),
"31" VARCHAR2(4000)
);
我得到的完整错误是:
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.driver.OracleStatement.checkBindsInAndOut(OracleStatement.java:1876)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2638)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at TestAms.doPost(TestAms.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我想在每一列中存储日期(已检查 jsp 页面中的单选按钮的日期)。
这是我的jsp页面。
提前致谢。