用jsp语句打开mysql语句,这样写正确么?
答案:1 悬赏:30 手机版
解决时间 2021-11-17 18:21
- 提问者网友:动次大次蹦擦擦
- 2021-11-17 00:27
用jsp语句打开mysql语句,这样写正确么?
最佳答案
- 五星知识达人网友:独行浪子会拥风
- 2021-11-17 01:35
试试这个,希望对你有帮助:
<%
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost/mydb?user=root&password=";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="SELECt * FROM tablename";
ResultSet rs = statement.executeQuery(sql);
out.print("记录编号");
out.print("|");
out.print("姓名");
out.print("
");
while(rs.next()) {
out.print(rs.getString(“id")+" ");
out.print("|");
out.print(rs.getString("name"));
out.print("
");
}
out.print("
");
out.print("数据库连接、查询操作已成功");
rs.close();
statement.close();
connection.close();
%>
<%
//驱动程序名
String driverName="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost/mydb?user=root&password=";
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="SELECt * FROM tablename";
ResultSet rs = statement.executeQuery(sql);
out.print("记录编号");
out.print("|");
out.print("姓名");
out.print("
");
while(rs.next()) {
out.print(rs.getString(“id")+" ");
out.print("|");
out.print(rs.getString("name"));
out.print("
");
}
out.print("
");
out.print("数据库连接、查询操作已成功");
rs.close();
statement.close();
connection.close();
%>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯