jsp连接MySQL数据库的简单方法-成都快上网建站

jsp连接MySQL数据库的简单方法

下面一起来了解下jsp连接MySQL数据库的简单方法,相信大家看完肯定会受益匪浅,文字在精不在多,希望jsp连接MySQL数据库的简单方法这篇短内容是你想要的。

创新互联自2013年起,是专业互联网技术服务公司,拥有项目网站制作、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元寿宁做网站,已为上家服务,为寿宁各地企业和个人服务,联系电话:18982081108

如果是使用eclipse将该包置于:
项目->WebContent->WEB-INF->lib下即可。

连接MySQL数据库代码:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>

<% 
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/mydata";
String user = "root";
String password = "root";
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, user, password);
Statement statement = conn.createStatement();
String sql = "select * from userInfo";
ResultSet rs = statement.executeQuery(sql);
String name = null;
String mima=null;
while (rs.next()) { 
 out.print("
用户名:"+rs.getString("username")+"密码:"+rs.getString("password")); } rs.close(); conn.close(); } catch (ClassNotFoundException e) { System.out.println("Sorry,can`t find the Driver!"); e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } %>

看完jsp连接MySQL数据库的简单方法这篇文章后,很多读者朋友肯定会想要了解更多的相关内容,如需获取更多的行业信息,可以关注我们的行业资讯栏目。


分享名称:jsp连接MySQL数据库的简单方法
网页URL:http://kswjz.com/article/ihgeis.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流