问题描述
- 求解!留言板代码哪里错了!抓狂啊
-
这段代码哪里出错了!这是一段留言板提交留言到数据库的代码,可是实验显示不能正确提交到数据库!求解!代码主体:<% String sql;String name=request.getParameter("name");if(name==null) {name=""; }String mail=request.getParameter("mail");if(mail==null) {mail=""; }String title=request.getParameter("title"); if(title==null) {title=""; }String content=request.getParameter("content"); if(content==null) {content=""; }if(name.length()==0) out.println("留言人的姓名不能为空!"); else if(title.length()==0) out.println("留言主题不能为空!"); else if(content.length()==0) out.println("留言内容不能为空!"); else { Class.forName("com.mysql.jdbc.Driver").newInstance(); String url="jdbc:mysql://localhost:3306/mydb"; Connection con=DriverManager.getConnection(url,"root","admin"); Statement stm=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);try { sql="Insert Into user(name,mail,title,content) Values('"+name+"','"+mail+"','"+title+"',"+content+")";stm.executeQuery(sql); } catch(Exception e) { out.println(e.getMessage());} ResultSet rs=stm.executeQuery("select * from user");rs.close();con.close(); %> <% } %>