JSP链接mySQL
来源:互联网 发布:开淘宝卖什么利润最高 编辑:程序博客网 时间:2024/06/12 20:51
test_mysql.jsp页面,代码如下:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>
<%
String driverName="com.mysql.jdbc.Driver";//驱动程序名
String userName="cl41";//数据库用户名
String userPasswd="880710";//密码
String dbName="db";//数据库名
String tableName="dbtest";//表名
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;//联结字符串
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);
ResultSetMetaData rmeta = rs.getMetaData();//获得数据结果集合
int numColumns=rmeta.getColumnCount();//确定数据集的列数,亦字段数
// 输出每一个数据值
out.print("id");
out.print("|");
out.print("num");
out.print("<br>");
while(rs.next()) {
out.print(rs.getString(1)+" ");
out.print("|");
out.print(rs.getString(2));
out.print("<br>");
}
out.print("<br>");
out.print("数据库操作成功,恭喜你");
rs.close();
statement.close();
connection.close();
%>
然后把test _mysql.jsp部署到tomcat处,如何部署可参考"配置Eclpise+tomcat并实现JSP的编写与部署",在浏览器中就可以看到结果了。
- jsp链接 mysql
- jsp链接 mysql
- JSP链接mySQL
- JSP链接mysql数据库
- JSP链接mySQL
- jsp链接MySQL
- linux JSP 链接Mysql数据库
- Jsp+Tomcat+Mysql搭建web项目 Jsp链接Mysql数据库
- jsp链接mysql出现乱码解决方法
- jsp 页面链接mysql数据库实现登陆
- web网页Eclipse,jsp+Servlet+javaBean,访问Mysql链接数据库
- JSP中链接MySQL数据库以及增删改查
- jsp与mysql数据库链接,插入等操作
- 链接mysql
- 链接mysql
- MySQL链接
- MySQL链接
- jsp页面链接
- win2008 R2 64位系统下配置DCOM权限
- 点滴
- C#中Split用法
- C++相关好帖
- Test
- JSP链接mySQL
- C++基础:纯虚函数和抽象类
- cfiledialog 打开目录出现乱码问题
- 解除ABAP程序编辑锁的方法
- 链表操作
- 学习linux编程
- C# Remove 两种删除字符方法
- RubyOnRails Windows版安装
- WM Format SDK 简介