2013年10月31日星期四

Failed to connect to MySQL using JDBC


<%
String userName =
new String (request. getParameter ("userName"). getBytes ("ISO-8859-1"), "UTF-8");
String password =
new String (request. getParameter ("password"). getBytes ("ISO-8859-1"), "UTF-8");
Connection con = null;
Statement st = null;
ResultSet rs = null;
if (userName.equals (""))
{
response.sendRedirect ("login.jsp");
}
try {
Class.forName ("com.mysql.jdbc.Driver" ) ;
String url = "jdbc: mysql :/ / localhost: 3306/eims? useUnicode = true & characterEncoding = gbk ";
con = DriverManager.getConnection (url, "root" , " 6785098 " ) ;
st = con.createStatement ();
String query = "select * from user where userName = '"+ userName +"' ";
rs = st.executeQuery (query);
if (rs.next ())
{
String query2 = ; "select * from user where password = '" + password + "'";
rs = st . executeQuery (query2);
if (rs.next ( ) )
{
response.sendRedirect ("main / main.jsp");
} else {
response.sendRedirect ("login.jsp");
}
}
} catch (Exception e) {
e.printStackTrace ();
} finally {
rs.close ();
st.close ();
con.close ();
}
%>

没有评论:

发表评论