日期:2014-05-18  浏览次数:20763 次

请大家推荐一个通用的数据库(MySQL、SQLServer、Oracle)操作类,Hibernate好象太复杂了,并且把数据库变的不象数据库了。
请大家推荐一个通用的数据库(MySQL、SQLServer、Oracle)操作类,Hibernate好象太复杂了,并且把数据库变的不象数据库了。

在一些产品性的开发应用中,觉得Hibernate太过复杂,不够灵活,并且不标准化,而是采用了它自己定义的HSQL,这对于产品的扩展和维护应该是不利的。

由于MySQL、SQLServer、Oracle在操作上会有一些不一样,比如分页机制等,是否能够做到开发上的通用?还是需要分别开发三种数据库版本的产品。

------解决方案--------------------
有点难,各个数据库都有点不同的。
sql都有点不同的。
帮忙up。
------解决方案--------------------
没听说哪个能行,帮顶。
------解决方案--------------------
使用设计模式中的工厂模式,自己定义通用数据库操作类。
1、定义接口:ISqlHelper
2、定义不同数据库的ISqlHelper的实现,如:MsSqlSqlHelper,OracleSqlHelper
3、定义工厂,返回ISqlHelper的实现;

参考思路,恕不提供代码。
------解决方案--------------------
使用Java中的反射来实现自己的通用的Dao啊
------解决方案--------------------
iBatis
绝对简单
------解决方案--------------------
其实也不复杂,书籍也多,还是容易学的
------解决方案--------------------
我写了一个 不嫌烂的话 拿去就是:
package com.gogou.common;

import java.util.*;
import java.sql.*;
import javax.servlet.jsp.jstl.sql.*;

/**
* This class is a bean for executing SQL statements. It has three
* properties that can be set: connection, sqlValue and values.
* The connection and sqlValue properties must always be set before
* calling one of the execute methods. If the values property is
* set, the sqlValue property must be an SQL statement with question
* marks as placeholders for the value objects in the values
* property.
*
* erdong
* @version 2.0
*/
public class SQLCommandBean {
private Connection conn;
private String sqlValue;
private List values;

public SQLCommandBean() {
try {
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String sConnStr =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=GoGou ";
Class.forName(sDBDriver);
this.conn = DriverManager.getConnection(sConnStr, "sa ", " ");
} catch (ClassNotFoundException ex) {
System.out.println( "at SQLCommandBean ClassNotFoundException ");
} catch (SQLException ex) {
System.out.println( "at SQLCommandBean SQLException ");
}
}

/**
* Sets the Connection to use.
*/
public void setConnection(Connection conn) {
this.conn = conn;
}

/**
* @param sqlValue String
*/
public void setCon() throws ClassNotFoundException, SQLException {
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String sConnStr =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=GoGou ";
Class.forName(sDBDriver);
this.conn = DriverManager.getConnection(sConnStr, "sa ", " ");
}

/**
* Set the SQL string, possibly with question mark placeholders for
* values set by setValues().
*/
public void setSqlValue(String sqlValue) {
this.sqlValue = sqlValue;
}

/**