用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心Java

一个操作数据库的Java Bean……

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 18:55:18
一个操作数据库的Java Bean,有兴趣的朋友看一下吧~~

package dbconnect;

import java.sql.*;

public class sqlconnection
{

String sDbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:sqlconnect"; // sqlconnect 数据源名称;
private Connection conn = null;
private Statement stmt = null;
ResultSet rs = null;

public sqlconnection()
{
try
{
Class.forName(sDbDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("sqlconnection():" + e.getMessage());
}
}

public ResultSet executeQuery(String sql)
{
rs = null;
try
{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}catch (SQLException ex){
System.err.println("aq.executeQuery:" + ex.getMessage());
}
return rs;
}

public void executeUpdate(String sql)
{
stmt = null;
rs = null;
try
{
conn = DriverManager.getConnection(sConnStr);
stmt = conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}catch (SQLException ex){
System.err.println("aq.executeQuery:" + ex.getMessage());
}
}

public void closeStmt()
{
try
{
stmt.close();
}catch (SQLException ex){
System.err.println("aq.executeQuery:" + ex.getMessage());
}
}

public void closeConn()
{
try
{
conn.close();
}catch (SQLException ex){
System.err.println("aq.executeQuery:" + ex.getMessage());
}
}
}


Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:23,734.38000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号