当前位置: 技术问答>java相关
誰能給個對數據庫操作的bean例子﹗分不斷送上﹗
来源: 互联网 发布时间:2015-02-25
本文导语: TMD那些人太保守了﹐我的思想是資源共享﹐他們確不那么想﹐還是在網上來找了﹗ | /* * @dbbean.java * Author:nicolas * Date:2001-3-21 * version:1.0v * Function:connect database,query table,update table by paramete...
TMD那些人太保守了﹐我的思想是資源共享﹐他們確不那么想﹐還是在網上來找了﹗
|
/*
* @dbbean.java
* Author:nicolas
* Date:2001-3-21
* version:1.0v
* Function:connect database,query table,update table by parameter
*/
package dbbean;
import java.sql.*;
import java.io.*;
public class dbbean{
//String sConnStr="jdbc:oracle:thin:@172.16.1.2:1521:labora","scott","tiger";
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
Connection conn=null;
ResultSet rs=null;
/*
* constructor:try to create a dababase driver
*/
public dbbean(){
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("dbbean(): "+e.getMessage());
}
}
public ResultSet executeQuery(String sqlStr){
rs=null;
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
}catch(SQLException e){
System.err.println("executeQuery(): "+e.getMessage());
}
return rs;
}
public int executeInsert(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeInsert(): "+e.getMessage());
return 0;//失败
}
}
public int executeUpdate(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeInsert(): "+e.getMessage());
return 0;//失败
}
}
public int executeDelete(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeDelete(): "+e.getMessage());
return 0;//失败
}
}
}
* @dbbean.java
* Author:nicolas
* Date:2001-3-21
* version:1.0v
* Function:connect database,query table,update table by parameter
*/
package dbbean;
import java.sql.*;
import java.io.*;
public class dbbean{
//String sConnStr="jdbc:oracle:thin:@172.16.1.2:1521:labora","scott","tiger";
String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
Connection conn=null;
ResultSet rs=null;
/*
* constructor:try to create a dababase driver
*/
public dbbean(){
try{
Class.forName(sDBDriver);
}catch(java.lang.ClassNotFoundException e){
System.err.println("dbbean(): "+e.getMessage());
}
}
public ResultSet executeQuery(String sqlStr){
rs=null;
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sqlStr);
}catch(SQLException e){
System.err.println("executeQuery(): "+e.getMessage());
}
return rs;
}
public int executeInsert(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeInsert(): "+e.getMessage());
return 0;//失败
}
}
public int executeUpdate(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeInsert(): "+e.getMessage());
return 0;//失败
}
}
public int executeDelete(String sqlStr){
try{
conn=DriverManager.getConnection("jdbc:odbc:wygl");
Statement stmt=conn.createStatement();
stmt.executeUpdate(sqlStr);
return 1;//成功
}catch(SQLException e){
System.err.println("executeDelete(): "+e.getMessage());
return 0;//失败
}
}
}
|
在http://www.chinajavaworld.com上
有一篇文章《一步一步用JBuilder開發EJB》的文章上有例子。
希望對你有幫助。
有一篇文章《一步一步用JBuilder開發EJB》的文章上有例子。
希望對你有幫助。