ds.default=jdbc/xxx
用户可以在自定义默认DAO类中通过java代码获取数据库连接,只需覆盖超类net.newxy.dbm.BaseDAO中public Connection getConnection(String dsJndi) throws Exception 方法,或实现抽象超类net.newxy.dbm.DBM中public Connection getConnection(String dsJndi) throws Exception 方法,例如:
package common;
import net.newxy.dbm.DBM;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DefaultDao extends DBM{
public Connection getConnection(String dsJndi) throws Exception {
Connection cn=null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
cn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/line_order?user=root&password=mysql");
} catch (ClassNotFoundException ex) {
} catch (IllegalAccessException ex) {
} catch (InstantiationException ex) {
} catch (SQLException ex1) {
throw new Exception(ex1.getMessage());
}
return cn;
}
}
在public Connection getConnection(String dsJndi) throws Exception 方法中参数String dsJndi被忽略。dao.default=common.DefaultDAO三、通过设置newxy.properties文件获得数据库连接 如果系统中没有数据源,则在src/下的newxy.properties文件中加入如下几行:
driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/line_order?user=root&password=mysql user=root pass=mysql