我正在尝试使用JDBC,ucanaccess驱动程序从JSP页面插入MS Access DB。不会播出任何错误,但不会将值插入数据库

同时使用类似的代码以显示表值(使用SELECT * from table)时,运行良好。但我无法在该表中插入

<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@page import ="java.sql.*"%>
<html>
<head><title>MS Access Insert</title></head>
<body>
<table border=1>
<tr><th>Student ID</th><th>Student Name</th></tr>
<%
Connection cn=null;
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

String url = "jdbc:ucanaccess://" + "C:/Users/6136532/Desktop/New folder/(4)/studentDB.mdb";

cn = DriverManager.getConnection(url);
Statement st=cn.createStatement();
st.execute("INSERT INTO studentDB VALUES (100, 18, 'Zara', 'Ali', prasad)");
%>

<%
//rs.close();
st.close();
cn.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
%>
</table>
</body>
</html>

最佳答案

您不能只插入未知参数prasad。所以:

st.execute("INSERT INTO studentDB VALUES (100, 18, 'Zara', 'Ali', 'prasad')");


要么:

String prasad = "Prasad Telang";
st.execute("INSERT INTO studentDB VALUES (100, 18, 'Zara', 'Ali', '" + prasad + "')");

09-28 15:04