JDBC连接没有密码的MySQL数据库

时间:2022-12-23 13:05:47
<%@ page contentType="text/html;charset=gb2312"%>   
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url ="jdbc:mysql://localhost/myblog?user=root& password=&useUnicode=true&characterEncoding=GB2312" ;
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
String query="select * from dlog_user";
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{
        String s=rs.getString("username");//看准你的字段是不是字符型,不然就不能用getString
        out.print(s+"<br>");
}
%>
</body>
</html>
 测试通过