我正在尝试插入到MS access DB从JSP页使用JDBC,ucanaccess驱动程序。未设定错误,但值不会插入到数据库中
虽然使用类似的代码来显示表值(使用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> 发布于 2015-04-09 15:11:17
你不能只是插入一个未知的参数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 + "')");https://stackoverflow.com/questions/29530322
复制相似问题