谁能给个ssh中 mysql的dao类代码 数据库部分
什么Class.forName("com.mysql.jdbc.Driver").什么的。。。用别的dao类可以继承这个类,从而访问数据库,急啊,谢了大神们。。。说明白了...
什么 Class.forName("com.mysql.jdbc.Driver").什么的 。。。
用别的dao类可以继承这个类,从而访问数据库,急啊 ,谢了大神们。。。
说明白了 就是 java链接mysql数据库 的basedao 展开
用别的dao类可以继承这个类,从而访问数据库,急啊 ,谢了大神们。。。
说明白了 就是 java链接mysql数据库 的basedao 展开
展开全部
DB接口:
package org.xxx.dbc;
import java.sql.Connection;
public interface IDatabaseConnection {
public Connection getConnection() throws Exception;
public void close() throws Exception;
}
------------------------------------------------------------------
实现:
package org.xxx.dbc.impl;
import java.sql.Connection;
import java.sql.DriverManager;
import org.xxx.dbc.IDatabaseConnection;
public class OracleDatabaseConnection implements IDatabaseConnection {
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:db1"; public static final String DBUSER = "name";
public static final String DBPASS = "pass";
private Connection conn = null;
@Override
public void close() throws Exception {
// TODO Auto-generated method stub
try {
if (this.conn != null) {
this.conn.close();
}
} catch (Exception e) {
throw e;
}
}
@Override
public Connection getConnection() throws Exception {
// TODO Auto-generated method stub
try {
Class.forName(DBDRIVER);
this.conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
} catch (Exception e) {
throw e;
}
return this.conn;
}
}
----------------------------------------------------------------------------------
工厂
package org.xxx.dbc.factory;
import org.xxx.dbc.IDatabaseConnection;
import org.xxx.dbc.impl.OracleDatabaseConnection;
public class DBCFactory {
public static IDatabaseConnection getOracleDatabaseConnection()throws Exception {
return new OracleDatabaseConnection();
}
}
看错了,以为是oracle .不影响使用
package org.xxx.dbc;
import java.sql.Connection;
public interface IDatabaseConnection {
public Connection getConnection() throws Exception;
public void close() throws Exception;
}
------------------------------------------------------------------
实现:
package org.xxx.dbc.impl;
import java.sql.Connection;
import java.sql.DriverManager;
import org.xxx.dbc.IDatabaseConnection;
public class OracleDatabaseConnection implements IDatabaseConnection {
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:db1"; public static final String DBUSER = "name";
public static final String DBPASS = "pass";
private Connection conn = null;
@Override
public void close() throws Exception {
// TODO Auto-generated method stub
try {
if (this.conn != null) {
this.conn.close();
}
} catch (Exception e) {
throw e;
}
}
@Override
public Connection getConnection() throws Exception {
// TODO Auto-generated method stub
try {
Class.forName(DBDRIVER);
this.conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
} catch (Exception e) {
throw e;
}
return this.conn;
}
}
----------------------------------------------------------------------------------
工厂
package org.xxx.dbc.factory;
import org.xxx.dbc.IDatabaseConnection;
import org.xxx.dbc.impl.OracleDatabaseConnection;
public class DBCFactory {
public static IDatabaseConnection getOracleDatabaseConnection()throws Exception {
return new OracleDatabaseConnection();
}
}
看错了,以为是oracle .不影响使用
展开全部
Class.forName("com.mysql.jdbc.Driver").这是jdbc连接数据库…… 真正的dao是在分层里的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
汗.....java链接mysql就七步啊...和链接sqlserver一样.
追问
就是以前复制粘贴惯了。。硬盘丢了。。记忆很模糊 就是basedao忘了 倒是会增删改查什么滴~
以前都是用一个类继承basedao,然后才和数据库交互。。现在 把“老大”basedao忘了啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
。。。SSH整合为什么要用JDBC ?自带的数据库连接池不是更好吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询