●jsp连接MySQL数据库 testmysql.jsp如下: <%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.sql.*"%> <html> <body> <%Class.forName("org.gjt.mm.mysql.Driver").newInstance(); String url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1" //testDB为你的数据库名 Connection conn= DriverManager.getConnection(url); Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql="select * from test"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()) {%> 您的第一个字段内容为:<%=rs.getString(1)%> 您的第二个字段内容为:<%=rs.getString(2)%> <%}%> <%out.print("数据库操作成功,恭喜你");%> <%rs.close(); stmt.close(); conn.close(); %> </body> </html>
JSP如何连接MYSQL数据库代码示例
来源:互联网 发布日期:2016-03-01 10:48:55 浏览:1467次
相关内容
AiLab云推荐
最新资讯
本月热点
热门排行
-
周鸿祎预测2024大模型10大趋势,“建议让AI在公司里无孔不入”
阅读量:186874
-
AI大变局,时代新希望|异想大会
阅读量:167156
-
产品经理必须懂得AI:ChatGPT-人工智能对话的新篇章
阅读量:107635
-
印媒:防AI造假,尼康、索尼等相机巨头拟推“数字签名”新技术
阅读量:104914
-
AI 的未来比你想象的更不稳定
阅读量:94547
-
比OpenAI官方提示词指南更全,这26条黄金准则让LLM性能飙升50%以上
阅读量:60890