怎么使用jsp连接mysql数据库
1个回答
展开全部
通过MySql数据库驱动程序连接
①driverClass=”com.mysql.jdbc.Driver”
②url=”jdbc:mysql://127.0.0.1:3306/mytest”
举个例子
连接数据库查询表的相关语句:
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mytest","root","");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from userinfo");
while(rs.next())
{
out.print("<br>用户名:"+rs.getString("username")+"密码:"+rs.getString("password"));
}
rs.close();
stmt.close();
conn.close();
①driverClass=”com.mysql.jdbc.Driver”
②url=”jdbc:mysql://127.0.0.1:3306/mytest”
举个例子
连接数据库查询表的相关语句:
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mytest","root","");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from userinfo");
while(rs.next())
{
out.print("<br>用户名:"+rs.getString("username")+"密码:"+rs.getString("password"));
}
rs.close();
stmt.close();
conn.close();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询