jsp中输入的数据怎么保存到数据库呢
<body>
<%
String number0 = request.getParameter("addnumber");
String name0 = request.getParameter("addname");
String birthday0 = request.getParameter("addbirthday");
String salary0 = request.getParameter("addsalary");
boolean flag = false;
%>
<%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=java";
String user = "sa";
String password1 = "LGJwsj965397075";
Connection conn = DriverManager.getConnection(url, user, password1);
PreparedStatement s1 = null;
try {
String sql = "insert into employee values(?,?,?,?)";
s1 = conn.prepareStatement(sql);
s1.setString(1, number0);
s1.setString(1, name0);
s1.setString(1, birthday0);
s1.setString(1, salary0);
flag =s1.execute();
// 依次关闭
s1.close();
conn.close();
} catch (Exception e) {
}
%>
<%
if (flag) {
%>
<jsp:forward page="success.jsp" />
<%
}else{
%>
添加失败!!!!!!!!!!!!
<%
}
%>
</body>
总是不成功
------解决方案--------------------s1.setString(1, number0);
s1.setString(1, name0);
s1.setString(1, birthday0);
s1.setString(1, salary0);
索引全是1?
------解决方案--------------------s1.setString(1, number0);
s1.setString(2, name0);
s1.setString(3, birthday0);
s1.setString(4, salary0);
------解决方案--------------------+1024