jsp中使用的mysql笔记

public static Connection getConnection() throws SQLException,
java.lang.ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/usermanager?useUnicode=true&characterEncoding=gbk";
String username = "root";
String password = "123";
Connection con = DriverManager.getConnection(url, username, password);
return con;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
res.setCharacterEncoding("utf-8");
String name=req.getParameter("name");
String pw=req.getParameter("pw");
name=new String(name.getBytes("ISO-8859-1"),"utf-8");
pw=new String(pw.getBytes("ISO-8859-1"),"utf-8");
try {
Connection con = getConnection();
Statement sql_statement = con.createStatement();
String query = "select * from user where uname=? and password=?";
PreparedStatement ps=con.prepareStatement(query);
ps.setString(1, name);ps.setString(2, pw);
ResultSet result = ps.executeQuery();

con.close();
} catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException");
System.err.println(e.getMessage());
} catch (SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}

jsp中使用的mysql笔记

上一篇:3DS MAX毛发修改器制作逼真仙人球


下一篇:Photoshop CS6教你如何使用吸管工具