- 浏览: 315068 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (195)
- 心情随想 (20)
- java基础 (30)
- 技术文章 (4)
- 在oracle的海洋中遨游 (25)
- unix (5)
- 没有意义 (6)
- 效率 (1)
- js (5)
- hibernate (2)
- jfreechart (3)
- 分析 (1)
- DW (2)
- on-line analytical processing (1)
- 人工智能理论 (10)
- weblogic (4)
- 我也cvs (0)
- TAM SSO 应用改造 (2)
- LADP (2)
- servlet (1)
- java 编码 (3)
- 智科 语录 (2)
- java 工作流 (1)
- swt (1)
- java pattern (1)
- xml和html基础 (19)
- c# (3)
- eclipse (1)
- db2 (4)
- 面试题 (0)
- english (2)
- Ruby (1)
- OLAP (3)
- 网友的智慧 (1)
- SOA (1)
- 搜索引擎 (4)
- 构建自己的报表工具 (1)
- JMX (1)
- 朝花朝拾 之少年记忆 (3)
- C语言 (2)
- struts2 (4)
- 元数据 数据仓库 (1)
- liferay (1)
- 分析工具 (0)
最新评论
-
yy8093:
只能在JDK1.4下监控WebLogic Server 8.x ...
weblogic JMX 中遇到的问题 -
di1984HIT:
问题找到了,就是1.4和1.5不兼容导致的,通过分析Objec ...
weblogic JMX 中遇到的问题_2 -
hillhill:
getServletContext().getRealPath ...
request.getRealPath("/") AIX不同与windows -
mrgood:
哥错了,这问题太傻逼了 一时没看出来
登录验证 struts2 -
mrgood:
LoginAction.java里面 if(getUserna ...
登录验证 struts2
package com.digitalchina.sitech.anhuibss.utils;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.*;
import java.sql.*;
import com.digitalchina.sitech.anhuibss.utils.JNDINames;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.digitalchina.sitech.anhuibss.exception.*;
import sun.jdbc.rowset.CachedRowSet;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright:
* 2007.12</p>
* <p>Company:</p>
* @author czk
* @version 1.0
*/
public class DBAction {
/***
* 使用调用:
* 一、
* 1、 private DBAction dbaction;
* 2、 dbaction = new DBAction();
* 3、 dbaction.setDBStmt(queryStr);
* 二、
* dbreturnvector = new Vector();
* dbreturnvector = dbaction.doSelect();
* */
protected static Log log = LogFactory.getLog(DBAction.class);
public String stmtstring = null;
private String msg = "";
private ResultSet rs = null;
private int columncount;
private int status = 0;
private Vector v = new Vector();
private Statement stmt = null;
private Connection dbConnection = null;
private DataSource datasource = null;
private java.sql.PreparedStatement pstmt = null;
public DBAction() throws ApplicationDAOException {
//部署时JNDI开启 (hyx)
/*
try {
InitialContext ic = new InitialContext();
datasource = (DataSource) ic.lookup(JNDINames.WEBBI_DATASOURCE);
}
catch (NamingException ne) {
throw new ApplicationDAOException("Naming Exception while looking "
+ " up DataSource Connection "
+ JNDINames.WEBBI_DATASOURCE + ": \n"
+ ne.getMessage());
}
*/
}
public DBAction(String dataSrc) throws ApplicationDAOException {
try {
InitialContext ic = new InitialContext();
if (dataSrc == null) {
dataSrc = JNDINames.WEBBI_DATASOURCE;
}
datasource = (DataSource) ic.lookup(dataSrc);
} catch (NamingException ne) {
throw new ApplicationDAOException("Naming Exception while looking "
+ "up DataSource Connection " + dataSrc + ": \n"
+ ne.getMessage());
}
}
/**
* Return the dbstmt.
*/
public String getDBStmt() {
return (this.stmtstring);
}
/**
* Set the dbstmt.
*
* @param dbstmt The new DB statement to execute
*/
public void setDBStmt(String stmtstring) {
this.stmtstring = stmtstring;
}
/**
* Return the db message.
*/
public String getDBString() {
return this.msg;
}
public String getSysDate() {
java.text.SimpleDateFormat formatter;
formatter = new java.text.SimpleDateFormat("yyyyMMdd");
String regdate;
regdate = formatter.format(new java.util.Date());
return regdate;
}
/**
* Return the dbreturn int.
*/
public int getDBInt() {
return this.status;
}
/**************************************************************
* 函数过程名:doSelectRs
* 名 称:得到结果集
* 创 建 者:czk
* 创建时间:2007.12-08-13
* 修 改 者:czk * 修改时间:2006.12-08-13
* ver :1.0
* 作用/用途:
* 得到结果集
* 注意事项:
* 在哪里使用这个方法,必须在哪里关闭(hyx)
* 例子:
*
finally {
try {
if (rs != null) {
rs.close();
}
dbaction.closeConnection();//注意事项的地方
}
catch (Exception e) {
log.error(e.getMessage(), e);
}
}
**************************************************************/
public ResultSet doSelectRs() throws ApplicationDAOException {
ResultSet result;
try {
getDBConnection();
stmt = null;
stmt = dbConnection.createStatement();
if (stmt == null) {
throw new ApplicationDAOException(
"DAO doSelectRs(e) stmt==null");
}
result = stmt.executeQuery(stmtstring);
return result;
} catch (Exception se) {
throw new ApplicationDAOException(
"SQLException CachedRowSet doSelectRsSet() "
+ " database table\n" + stmtstring + " :\n"
+ se.toString());
}
}
/**
* Handle database update
*/
public int doUpdate() throws ApplicationDAOException {
this.msg = "";
this.status = 0;
try {
if (dbConnection == null || dbConnection.isClosed()) {
getDBConnection();
}
stmt = null;
stmt = dbConnection.createStatement();
if (stmt == null) {
throw new ApplicationDAOException("DAO doUpdate() stmt==null");
}
status = stmt.executeUpdate(stmtstring);
} catch (SQLException ae) {
this.msg = ae.getMessage();
throw new ApplicationDAOException("SQLException while inserting "
+ "database table \n" + stmtstring + " :\n" + ae);
} finally {
closeConnection();
}
return this.status;
}
public String[][] doSelectRs(String sql) throws ApplicationDAOException {
ResultSet result;
String[][] data;
try {
getDBConnection();
stmt = null;
stmt = dbConnection.createStatement();
if (stmt == null) {
throw new ApplicationDAOException(
"DAO doSelectRs(e) stmt==null");
}
result = stmt.executeQuery(sql);
data = getStringArrayFromRS(result);
return data;
} catch (Exception se) {
throw new ApplicationDAOException(
"SQLException doSelectRs() "
+ " database table\n" + stmtstring + " :\n"
+ se.toString());
} finally {
closeConnection();
}
}
public ResultSet doPrepageSelectSql() throws ApplicationDAOException {
ResultSet result;
try {
getDBConnection();
stmt = null;
stmt = dbConnection.prepareStatement(stmtstring);
if (stmt == null) {
throw new ApplicationDAOException(
"DAO doSelectRs(e) stmt==null");
}
result = stmt.executeQuery(stmtstring);
return result;
} catch (Exception se) {
throw new ApplicationDAOException(
"SQLException CachedRowSet doSelectRsSet() "
+ " database table\n" + stmtstring + " :\n"
+ se.toString());
} finally {
closeConnection();
}
}
public String[][] getStringArrayFromRS(ResultSet rs) {
String[][] data = null;
try {
ResultSetMetaData rsmeta = rs.getMetaData();
int dataCols = rsmeta.getColumnCount();
Vector rows = new Vector();
int dataRows = 0;
while (rs.next()) {
String[] row = new String[dataCols];
for (int i = 0; i < dataCols; i++) {
String s = rs.getString(i + 1) == null ? "" : rs.getString(
i + 1).trim();
row[i] = s;
}
rows.addElement(row);
dataRows++;
}
if (dataRows > 0) {
data = new String[dataRows][dataCols];
for (int i = 0; i < dataRows; i++) {
data[i] = (String[]) rows.elementAt(i);
}
}
} catch (Exception e) {
}
return data;
}
/**
* Method for get connection with database
*/
public Connection getDBConnection() throws ApplicationDAOException {
try {
DriverManager.registerDriver(new com.ibm.db2.jcc.DB2Driver());
String url = "jdbc:db2://130.30.6.34:50000/bssdb";
String userName = "papp";
String password = "papp";
dbConnection = DriverManager.getConnection(url, userName, password);
//dbConnection = datasource.getConnection();
} catch (SQLException se) {
throw new ApplicationDAOException("SQL Exception while getting "
+ "DB connection : \n" + se);
}
return dbConnection;
}
public String getEquiteID(String strEquipType)
throws ApplicationDAOException {
// sbdz-20040813-000001
String retStrID = "";
// strSeq_num默认为1 第一单
String strSeq_num = "1";
int intSeqNum = 0;
ResultSet rs = null;
try {
/*
* 先要判断是否存在该类型的记录,如果不存在增加一条记录. BY JOHNY 2006.07.17
*/
String stmtString = "";
String queryStr = "select seq_num from t_common_sequence_key "
+ " where seq_type = '" + strEquipType + "'";
setDBStmt(queryStr);
rs = doSelectRs();
if (!rs.next()) {
queryStr = "insert into t_common_sequence_key(seq_type,seq_name,seq_date,seq_num)"
+ "values ('"
+ strEquipType
+ "','未定义类型','"
+ getSysDate() + "',0)";
setDBStmt(queryStr);
doUpdate();
}
queryStr = "select seq_num from t_common_sequence_key "
+ " where seq_type = '" + strEquipType + "'"
+ " and seq_date='" + getSysDate() + "'";
setDBStmt(queryStr);
rs = doSelectRs();
if (rs.next()) {
// 最大流水号 加1
intSeqNum = (rs.getInt(1) + 1);
stmtString = "update t_common_sequence_key "
+ " set seq_num=seq_num+1 " + " where seq_type = '"
+ strEquipType + "'" + " and seq_date='" + getSysDate()
+ "'";
// 更新操作
setDBStmt(stmtString);
doUpdate();
strSeq_num = String.valueOf(intSeqNum);
} else {
stmtString = "update t_common_sequence_key "
+ " set seq_num=1 ,seq_date='" + getSysDate() + "'"
+ " where seq_type = '" + strEquipType + "'";
setDBStmt(stmtString);
doUpdate();
} // else
// 没有7位数 前补0
while (strSeq_num.length() < 7) {
strSeq_num = "0" + strSeq_num;
}
retStrID = strEquipType + "-" + getSysDate() + "-" + strSeq_num;
} catch (Exception se) {
log.error(se.getMessage(), se);
} finally {
try {
if (rs != null) {
rs.close();
}
closeConnection();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
return retStrID;
}
/**
* Close database conection.
*/
public void closeConnection() throws ApplicationDAOException {
try {
if (dbConnection != null && !dbConnection.isClosed()) {
if (stmt != null) {
stmt.close();
}
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
dbConnection.close();
}
} catch (SQLException se) {
throw new ApplicationDAOException("SQL Exception while closing "
+ "DB connection : \n" + se);
}
}
/**************************************************************
* <p>名称:destroy() <br>
* 创建者:
* 创建时间:2006.12 <br>
* 修 改 者:<br>
* 修改时间:2006.12 <br>
* 处理流程: <br>
****************************************************************/
public void destroy() {
//Clean up resources
}
/**
* get dbConnection
* @throws ApplicationDAOException
*/
public Connection getConnection() throws ApplicationDAOException {
try {
if (dbConnection == null || dbConnection.isClosed()) {
getDBConnection();
}
return dbConnection;
} catch (SQLException se) {
throw new ApplicationDAOException(
"SQL Exception while getConnection() : \n " + se);
}
}
public static void main(String args[]) {
try {
DBAction dbaction = new DBAction();
dbaction.stmtstring = "select * from papp.t_sys_web_user";
ResultSet rs = dbaction.doSelectRs();
while (rs.next()) {
String tmp = rs.getString(1);
System.out.println(tmp);
}
dbaction.closeConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.*;
import java.sql.*;
import com.digitalchina.sitech.anhuibss.utils.JNDINames;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.digitalchina.sitech.anhuibss.exception.*;
import sun.jdbc.rowset.CachedRowSet;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright:
* 2007.12</p>
* <p>Company:</p>
* @author czk
* @version 1.0
*/
public class DBAction {
/***
* 使用调用:
* 一、
* 1、 private DBAction dbaction;
* 2、 dbaction = new DBAction();
* 3、 dbaction.setDBStmt(queryStr);
* 二、
* dbreturnvector = new Vector();
* dbreturnvector = dbaction.doSelect();
* */
protected static Log log = LogFactory.getLog(DBAction.class);
public String stmtstring = null;
private String msg = "";
private ResultSet rs = null;
private int columncount;
private int status = 0;
private Vector v = new Vector();
private Statement stmt = null;
private Connection dbConnection = null;
private DataSource datasource = null;
private java.sql.PreparedStatement pstmt = null;
public DBAction() throws ApplicationDAOException {
//部署时JNDI开启 (hyx)
/*
try {
InitialContext ic = new InitialContext();
datasource = (DataSource) ic.lookup(JNDINames.WEBBI_DATASOURCE);
}
catch (NamingException ne) {
throw new ApplicationDAOException("Naming Exception while looking "
+ " up DataSource Connection "
+ JNDINames.WEBBI_DATASOURCE + ": \n"
+ ne.getMessage());
}
*/
}
public DBAction(String dataSrc) throws ApplicationDAOException {
try {
InitialContext ic = new InitialContext();
if (dataSrc == null) {
dataSrc = JNDINames.WEBBI_DATASOURCE;
}
datasource = (DataSource) ic.lookup(dataSrc);
} catch (NamingException ne) {
throw new ApplicationDAOException("Naming Exception while looking "
+ "up DataSource Connection " + dataSrc + ": \n"
+ ne.getMessage());
}
}
/**
* Return the dbstmt.
*/
public String getDBStmt() {
return (this.stmtstring);
}
/**
* Set the dbstmt.
*
* @param dbstmt The new DB statement to execute
*/
public void setDBStmt(String stmtstring) {
this.stmtstring = stmtstring;
}
/**
* Return the db message.
*/
public String getDBString() {
return this.msg;
}
public String getSysDate() {
java.text.SimpleDateFormat formatter;
formatter = new java.text.SimpleDateFormat("yyyyMMdd");
String regdate;
regdate = formatter.format(new java.util.Date());
return regdate;
}
/**
* Return the dbreturn int.
*/
public int getDBInt() {
return this.status;
}
/**************************************************************
* 函数过程名:doSelectRs
* 名 称:得到结果集
* 创 建 者:czk
* 创建时间:2007.12-08-13
* 修 改 者:czk * 修改时间:2006.12-08-13
* ver :1.0
* 作用/用途:
* 得到结果集
* 注意事项:
* 在哪里使用这个方法,必须在哪里关闭(hyx)
* 例子:
*
finally {
try {
if (rs != null) {
rs.close();
}
dbaction.closeConnection();//注意事项的地方
}
catch (Exception e) {
log.error(e.getMessage(), e);
}
}
**************************************************************/
public ResultSet doSelectRs() throws ApplicationDAOException {
ResultSet result;
try {
getDBConnection();
stmt = null;
stmt = dbConnection.createStatement();
if (stmt == null) {
throw new ApplicationDAOException(
"DAO doSelectRs(e) stmt==null");
}
result = stmt.executeQuery(stmtstring);
return result;
} catch (Exception se) {
throw new ApplicationDAOException(
"SQLException CachedRowSet doSelectRsSet() "
+ " database table\n" + stmtstring + " :\n"
+ se.toString());
}
}
/**
* Handle database update
*/
public int doUpdate() throws ApplicationDAOException {
this.msg = "";
this.status = 0;
try {
if (dbConnection == null || dbConnection.isClosed()) {
getDBConnection();
}
stmt = null;
stmt = dbConnection.createStatement();
if (stmt == null) {
throw new ApplicationDAOException("DAO doUpdate() stmt==null");
}
status = stmt.executeUpdate(stmtstring);
} catch (SQLException ae) {
this.msg = ae.getMessage();
throw new ApplicationDAOException("SQLException while inserting "
+ "database table \n" + stmtstring + " :\n" + ae);
} finally {
closeConnection();
}
return this.status;
}
public String[][] doSelectRs(String sql) throws ApplicationDAOException {
ResultSet result;
String[][] data;
try {
getDBConnection();
stmt = null;
stmt = dbConnection.createStatement();
if (stmt == null) {
throw new ApplicationDAOException(
"DAO doSelectRs(e) stmt==null");
}
result = stmt.executeQuery(sql);
data = getStringArrayFromRS(result);
return data;
} catch (Exception se) {
throw new ApplicationDAOException(
"SQLException doSelectRs() "
+ " database table\n" + stmtstring + " :\n"
+ se.toString());
} finally {
closeConnection();
}
}
public ResultSet doPrepageSelectSql() throws ApplicationDAOException {
ResultSet result;
try {
getDBConnection();
stmt = null;
stmt = dbConnection.prepareStatement(stmtstring);
if (stmt == null) {
throw new ApplicationDAOException(
"DAO doSelectRs(e) stmt==null");
}
result = stmt.executeQuery(stmtstring);
return result;
} catch (Exception se) {
throw new ApplicationDAOException(
"SQLException CachedRowSet doSelectRsSet() "
+ " database table\n" + stmtstring + " :\n"
+ se.toString());
} finally {
closeConnection();
}
}
public String[][] getStringArrayFromRS(ResultSet rs) {
String[][] data = null;
try {
ResultSetMetaData rsmeta = rs.getMetaData();
int dataCols = rsmeta.getColumnCount();
Vector rows = new Vector();
int dataRows = 0;
while (rs.next()) {
String[] row = new String[dataCols];
for (int i = 0; i < dataCols; i++) {
String s = rs.getString(i + 1) == null ? "" : rs.getString(
i + 1).trim();
row[i] = s;
}
rows.addElement(row);
dataRows++;
}
if (dataRows > 0) {
data = new String[dataRows][dataCols];
for (int i = 0; i < dataRows; i++) {
data[i] = (String[]) rows.elementAt(i);
}
}
} catch (Exception e) {
}
return data;
}
/**
* Method for get connection with database
*/
public Connection getDBConnection() throws ApplicationDAOException {
try {
DriverManager.registerDriver(new com.ibm.db2.jcc.DB2Driver());
String url = "jdbc:db2://130.30.6.34:50000/bssdb";
String userName = "papp";
String password = "papp";
dbConnection = DriverManager.getConnection(url, userName, password);
//dbConnection = datasource.getConnection();
} catch (SQLException se) {
throw new ApplicationDAOException("SQL Exception while getting "
+ "DB connection : \n" + se);
}
return dbConnection;
}
public String getEquiteID(String strEquipType)
throws ApplicationDAOException {
// sbdz-20040813-000001
String retStrID = "";
// strSeq_num默认为1 第一单
String strSeq_num = "1";
int intSeqNum = 0;
ResultSet rs = null;
try {
/*
* 先要判断是否存在该类型的记录,如果不存在增加一条记录. BY JOHNY 2006.07.17
*/
String stmtString = "";
String queryStr = "select seq_num from t_common_sequence_key "
+ " where seq_type = '" + strEquipType + "'";
setDBStmt(queryStr);
rs = doSelectRs();
if (!rs.next()) {
queryStr = "insert into t_common_sequence_key(seq_type,seq_name,seq_date,seq_num)"
+ "values ('"
+ strEquipType
+ "','未定义类型','"
+ getSysDate() + "',0)";
setDBStmt(queryStr);
doUpdate();
}
queryStr = "select seq_num from t_common_sequence_key "
+ " where seq_type = '" + strEquipType + "'"
+ " and seq_date='" + getSysDate() + "'";
setDBStmt(queryStr);
rs = doSelectRs();
if (rs.next()) {
// 最大流水号 加1
intSeqNum = (rs.getInt(1) + 1);
stmtString = "update t_common_sequence_key "
+ " set seq_num=seq_num+1 " + " where seq_type = '"
+ strEquipType + "'" + " and seq_date='" + getSysDate()
+ "'";
// 更新操作
setDBStmt(stmtString);
doUpdate();
strSeq_num = String.valueOf(intSeqNum);
} else {
stmtString = "update t_common_sequence_key "
+ " set seq_num=1 ,seq_date='" + getSysDate() + "'"
+ " where seq_type = '" + strEquipType + "'";
setDBStmt(stmtString);
doUpdate();
} // else
// 没有7位数 前补0
while (strSeq_num.length() < 7) {
strSeq_num = "0" + strSeq_num;
}
retStrID = strEquipType + "-" + getSysDate() + "-" + strSeq_num;
} catch (Exception se) {
log.error(se.getMessage(), se);
} finally {
try {
if (rs != null) {
rs.close();
}
closeConnection();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
return retStrID;
}
/**
* Close database conection.
*/
public void closeConnection() throws ApplicationDAOException {
try {
if (dbConnection != null && !dbConnection.isClosed()) {
if (stmt != null) {
stmt.close();
}
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
dbConnection.close();
}
} catch (SQLException se) {
throw new ApplicationDAOException("SQL Exception while closing "
+ "DB connection : \n" + se);
}
}
/**************************************************************
* <p>名称:destroy() <br>
* 创建者:
* 创建时间:2006.12 <br>
* 修 改 者:<br>
* 修改时间:2006.12 <br>
* 处理流程: <br>
****************************************************************/
public void destroy() {
//Clean up resources
}
/**
* get dbConnection
* @throws ApplicationDAOException
*/
public Connection getConnection() throws ApplicationDAOException {
try {
if (dbConnection == null || dbConnection.isClosed()) {
getDBConnection();
}
return dbConnection;
} catch (SQLException se) {
throw new ApplicationDAOException(
"SQL Exception while getConnection() : \n " + se);
}
}
public static void main(String args[]) {
try {
DBAction dbaction = new DBAction();
dbaction.stmtstring = "select * from papp.t_sys_web_user";
ResultSet rs = dbaction.doSelectRs();
while (rs.next()) {
String tmp = rs.getString(1);
System.out.println(tmp);
}
dbaction.closeConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
}
发表评论
-
BufferedInputStream 测试
2009-04-20 16:37 1661在读取arff文件的时候,有点是需要注意到的。在J ... -
获取Java程序运行的路径
2009-04-20 13:04 9601关键字: jar war 运行路径 对于Java程序,无论是 ... -
数字的正则表达式
2009-03-21 17:12 1482(\d{3}-|\d{4}-)?(\d{8}|\d{7})? ... -
jsp相关
2009-01-20 14:25 1006<% response.setHeader(" ... -
java 对文本的写和读
2008-09-04 21:31 891-----------写操作 File file=n ... -
byte,char int 之间关系即转换
2008-06-23 16:49 2812曾经遇到一个问题 char word='a',转换成'b'的问 ... -
使用DatabaseMetaDate获取数据库信息
2008-06-06 08:00 1412import java.sql.*; public class ... -
ant 的学习点滴
2008-06-03 08:31 1196一环境 1:ANT的项目的地址为 http://ant.a ... -
throws 和 try catch 的区别
2008-05-29 11:37 1402/** * 获取查询的result * @param ... -
Utf-8编码是如何工作的 (转改)
2008-05-26 11:18 1822关键字: 编码 Utf-8编码是如何工作的讲起。 (JVM规范 ... -
jdom和gnujaxp冲突的解决
2008-05-20 21:37 1380在网上看有: java.net.MalformedURLExc ... -
java异常中Runtime点滴学习
2008-05-19 09:22 1992特别关注一下 RuntimeExcep ... -
java 中的增量操作
2008-05-14 08:11 970public class Increment { /** ... -
JMX 基础及实例
2008-05-07 10:25 1577JMX Java Management Extensions ... -
weblogic 下excel乱码问题的解决
2008-05-06 18:30 2333在web.xml中配置 <mime-mappin ... -
小例子来证明String不同于StringBuffer
2008-04-06 11:44 916String 和 ... -
java 初学者必须理解的六大问题(转载)
2008-03-28 18:11 827对于这个系列里的问题,每个学Java的人都应该搞懂。当然,如果 ... -
path
2008-02-23 11:44 1016在j2ee开发的过程中经常要获取path的信息 java 如果 ... -
package
2008-02-20 15:06 892在执行class文件的时候,是要进行打包操作的 怎么packa ... -
连接与 连接池
2008-02-19 17:00 963我们可以维护一个进入的连接池,一定数量的 Connection ...
相关推荐
本文将深入探讨如何使用Java代码来实现一个简单的数据库连接池,并解释其核心概念和工作原理。 连接池的基本思想是维护一组预初始化的数据库连接,当应用程序需要时,可以从池中获取一个连接,使用完毕后,再归还回...
### JAVA 使用数据库连接池连接Oracle数据库全代码解析 #### 一、概述 本文将详细介绍如何在Java项目中使用Apache DBCP(Database Connection Pool)来连接Oracle数据库,并提供完整的示例代码。通过这种方式,我们...
"Oracle根据数据库自动生成JAVA代码"这一技术就是将数据库中的表结构映射到Java编程语言中的实体类、DAO(Data Access Object)、Service、Controller以及前端展示层的HTML模板,从而减少手动编写这些基础代码的工作...
此外,为了提高代码的健壮性和可维护性,通常会使用连接池(如C3P0、Apache DBCP或HikariCP),它管理数据库连接,避免频繁创建和关闭连接,提高性能。 在实际开发中,我们还需要关注异常处理,确保在发生错误时能...
jdbcUrl、jdbcUser、jdbcPwd都需要配置成所需要连接的数据库信息 packageName:可按照项目中名称配置 tableList:配置成数据库表名,中间以逗号隔开 2、配置start.bat 配置config.path=本地的mybatisplus.json...
它提供了加载数据库驱动、建立数据库连接、执行SQL语句以及处理查询结果等方法。 2. 连接数据库的关键步骤: - 注册JDBC驱动:通过`Class.forName()`方法加载对应数据库的JDBC驱动类,并实例化。 - 获取数据库...
程序实现了使用Java语言编程实现对数据库的访问,所有的SQL操作均在自己建立的新库里进行,数据库建议选用学生课程数据库,可以选择进行创建、插入、查询、删除和更新等操作,其中查询操作可以按学号、姓名、专业...
JAVA与数据库的连接代码,需要添加支持mysql的架包才能使用。。。
java代码-使用java解决数据库连接的源代码 ——学习参考资料:仅用于个人学习使用!
在给定的“java数据库连接池源代码”中,我们可以看到以下几个关键组成部分: 1. **测试文件TestConnect.java**:这是一个用于验证数据库连接池功能是否正常的测试程序。它通常包含一些基础的数据库操作,如打开...
3. **Java代码示例**:以下是一个简单的Java代码示例,展示如何使用JDBC连接Cache数据库: ```java import java.sql.*; public class CacheConnectionExample { public static void main(String[] args) { ...
在Java课程设计中,数据库连接是至关重要的环节,它涉及到如何与存储数据的服务器进行通信,获取并操作数据。在本项目中,我们将探讨如何实现合法登录数据库,并通过JSP(JavaServer Pages)来对数据库中的内容进行...
开发者可以在该文件中指定数据库连接信息、生成的目标包名、类名前缀等,并可以定义模板来自定义生成的代码风格。例如,你可以设置是否生成通用的Mapper接口,以及如何处理日期字段等。 使用说明.txt文件很可能是对...
接下来,我们可以编写Java代码来建立数据库连接。以下是一个简单的示例: ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Main { public ...
### Java 数据库连接泄漏及其解决方法 #### 一、引言 在软件开发过程中,特别是在使用Java进行Web应用开发时,数据库连接管理是一项至关重要的任务。不当的连接管理会导致资源浪费,甚至引发系统性能问题。其中,...
在"java数据库连接方法.doc"文档中,可能详细展示了如何在Java代码中实现上述步骤,包括加载驱动、创建连接、执行SQL以及关闭资源的示例。通过阅读文档,你可以更好地理解这些概念,并能在实际项目中运用。 总的来...
一个简单的java编写,通过jdbc连接sqlserver数据库的代码,其中可以用config.txt来配置数据库连接,需要根据电脑情况,修改代码中的文件路径即可食用。此代码连接了数据库并且输出一个student表。
JDBC提供了四种数据库连接方式:JDBC-ODBC桥接,JDBC网络纯Java驱动,JDBC本地协议纯Java驱动,以及JNDI查找。 2. **DBMS介绍:MySQL**: MySQL是一款流行的开源关系型数据库管理系统,以其高效、稳定和易于管理而...
一旦建立了数据库连接,就可以通过 `PreparedStatement` 或 `Statement` 对象来执行 SQL 语句。示例代码中提供了两种主要的 SQL 执行方法: 1. **执行查询(Select)**: ```java ResultSet rs = psmt....
本教程涵盖了一系列关于Java中数据库连接的重要知识点,包括基础概念、API使用、代码示例以及数据库管理操作。以下是对这些主题的详细解释: 1. **JDBC(Java Database Connectivity)**: JDBC是Java平台的标准...