社区
Linux/Unix社区
帖子详情
jsp与mysql的连接
mht100
2004-09-29 11:24:39
tomvat5.3下作的Jsp网站如何与mysql的数据库相连呢?(已经写好class文件)谢谢!
...全文
64
3
打赏
收藏
jsp与mysql的连接
tomvat5.3下作的Jsp网站如何与mysql的数据库相连呢?(已经写好class文件)谢谢!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
xharry
2004-10-12
打赏
举报
回复
这个是一个javabean,jsp用的
package DBase;
import java.sql.*;
public class Conn{
String DBDriver="org.gjt.mm.mysql.Driver";
String ConnStr="jdbc:mysql://localhost/netkiss?useUnicode=true&characterEncoding=ISO-8859-1";
String MyUser="root";
String MyPassword="";
Connection conn = null;
ResultSet rs = null;
/*****************************************************************
*函数名 :connect
*功能 :连接数据库
*作成日 :28/04/2003
*****************************************************************/
public void connect(){
try{
Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException e)
{System.err.println("DBconn (): " + e.getMessage());
}
}
/*****************************************************************
*函数名 :executeUpdate
*功能 :插入、更新数据库
*作成日 :28/04/2003
*****************************************************************/
public int executeUpdate(String sql){
int update=-1;
try{
conn = DriverManager.getConnection(ConnStr,MyUser,MyPassword);
Statement stmt = conn.createStatement();
update = stmt.executeUpdate(sql);
}
catch(SQLException ex)
{System.err.println("aq.executeQuery:"+ex.getMessage());
}
return update;
}
/****************************************************************
*函数名 :executeQuery
*功能 :查询数据库
*作成日 :28/04/2003
****************************************************************/
public ResultSet executeQuery(String sql){
rs = null;
try{
conn = DriverManager.getConnection(ConnStr,MyUser,MyPassword);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
/***************************************************************
*函数名 :disconnect()
*功能 :断开数据库连接
*作成日 :28/04/2003
***************************************************************/
public void disconnect(){
try{
if (conn!=null){
conn.close();
}
}catch (SQLException sqle){
System.err.println(sqle.getMessage());
}
}
}
evener
2004-10-11
打赏
举报
回复
选一个合适你的^_^
evener
2004-10-11
打赏
举报
回复
先下载安装JDBC驱动程序。有4种,在http://industry.java.sun.com/products/jdbc/drivers可以找到并下载。
Linux/Unix社区
23,215
社区成员
74,540
社区内容
发帖
与我相关
我的任务
Linux/Unix社区
Linux/Unix社区 应用程序开发区
复制链接
扫一扫
分享
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章