无法在MS Access DB中插入

时间:2015-04-09 05:18:30

标签: java ms-access netbeans

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

虽然使用类似的代码来显示表值(使用表中的SELECT *),但运行正常。但我无法在该表中插入

<%@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> 

1 个答案:

答案 0 :(得分:1)

您无法插入未知参数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 + "')");