我想用 jsp 代码向 mysql 数据库中插入行,但我不能。这是我没有 html 表单的 jsp 代码:
<%
String login = request.getParameter("login");
String password = request.getParameter("password");
String full_name = request.getParameter("full_name");
String ulevel = request.getParameter("ulevel");
String team_id = request.getParameter("team_id");
Connection connection = null;
PreparedStatement pstatement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
if(login!=null && password!=null && full_name!=null && ulevel!=null && team_id!=null){
if(login!="" && password!="" && full_name!="" && ulevel!="" && team_id!="") {
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/android","root","root");
String queryString = "INSERT INTO users(user_id,login,password,full_name,ulevel,team_id) VALUES (null, ?, ?, ?, ?, ?)";
pstatement = connection.prepareStatement(queryString);
pstatement.setString(2, login);
pstatement.setString(3, password);
pstatement.setString(4, full_name);
pstatement.setString(5, ulevel);
pstatement.setString(6, team_id);
updateQuery = pstatement.executeUpdate();
if (updateQuery != 0) { %>
当我按 SUBMIT 时,网页会显示:
类型状态报告消息描述请求的资源()不可用。
ps: mysql 表中的列user_id
设置为,所以我使用.autoincrement
null
但我不知道,这是正确的方法......
我从 netbeans 7.0.1 运行代码