JSP连接DB2数据库
2018-07-20 来源:open-open
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
String url = "jdbc: db2://localhost:5000/sample";
//sample为你的数据库名
String user = "admin";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
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>
标签: 数据库
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:百度与谷歌地图坐标转换代码
下一篇: python 去除html标签的代码
最新资讯
热门推荐