jsp链接mysql数据库

 1 <%
 2     Class.forName("com.mysql.jdbc.Driver");
 3     Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/discuz","root","");
 4     Statement stmt=conn.createStatement();
 5     ResultSet rs=stmt.executeQuery("select * from pre_common_block");
 6     while(rs.next())
 7     {
 8     out.print("<br>用户名:"+rs.getString("name")+"密码:"+rs.getString("name"));
 9     }
10     rs.close();
11    stmt.close();
12    conn.close();
13 %>

注意:在tomcat中lib文件中要加入mysql-connector-java-5.1.7-bin 包

你可能感兴趣的:(jsp链接mysql数据库)