Jsp连接MySql
2006-12-18 16:09
232 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
jsp连接MySQL数据库
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
testmysql.jsp如下:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ page contentType="text/html;charset=gb2312"%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%@ page import="java.sql.*"%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
String url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//testDB为你的数据库名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Connection conn= DriverManager.getConnection(url);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
String sql="select * from test";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ResultSet rs=stmt.executeQuery(sql);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
while(rs.next()) ...{%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
您的第一个字段内容为:<%=rs.getString(1)%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
您的第二个字段内容为:<%=rs.getString(2)%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
<%}%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%out.print("数据库操作成功,恭喜你");%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<%rs.close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
stmt.close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
conn.close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
%>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
相关文章推荐
- jsp连接mysql 数据库
- jsp+tomcat+mysql的数据连接问题之亲身体验!
- [ASP/PHP/JSP]MySQL5.0中文问题及JDBC数据库连接和JSP汉字编码问题解决方法总结
- jsp连接mysql
- jsp连接Mysql--查询操作
- Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台) 选择自 dazern 的 Blog
- jsp连接mysql的增删改操作
- JSP 连接MySQL配置与使用
- JSP连接MySQL时老是遇到驱动错误怎么办?
- jsp连接mysql----------第一篇技术类文章
- JSP和MySQL连接
- Jsp,JavaBean,Mysql的连接方法
- JSP 连接各类数据库大全(Oracle,MSSQL,DB2,Informix,SyBASE,MYSQL,PostgreSQL)
- JSP中通过JDBC连接数据库mysql
- jsp中连接mysql的javabean
- Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
- jsp连接mysql
- jsp如何连接oracle 和 mysql ,sqlserver
- JSP MySQL JSP连接MySQL
- jsp连接MySQL实现插入insert操作