向Mysql中插入数据
本帖最后由 cheerful9001 于 2013-07-23 08:48:38 编辑
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest req,HttpServletResponse resp)
throws
ServletException,
IOException{
process(req,resp);
}
protected void doPost(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException {
process(req,resp);
}
private void process(HttpServletRequest req,HttpServletResponse resp)
throws IOException{
try{
String username = req.getParameter("username");
String password=req.getParameter("password");
String sql="insert into bool(name,password) values("+username+","+password+")";
String uri = "jdbc:mysql://localhost:3306/test";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("com.jdbc.mysql.Driver");
}catch(Exception e){
System.out.println(e);
}
try{
conn = DriverManager.getConnection(uri,"root","wanglihui");
stmt = conn.createStatement();
stmt.executeQuery(sql);
}catch(Exception e){
System.out.println(e);
}
conn.close();
/////////////////JSP
<form action = "./Login" method = "post">
username:<input type="text" name="username"><br>
password:<input type="password" name="password"><br>
<input type="submit" value="submit">
<input type ="reset" value="reset"><br>
</form>
求指教 为什么在数据库中查询不到添加的内容呢??