use of java.sql.PreparedStatement in project translationstudio8 by heartsome.
the class SystemDBOperator method addSysDb.
/**
* 插入系统库
* @param dbName
* 数据库名称
* @param quality
* 是否优化
*/
public void addSysDb(String dbName, String quality, int type) {
MetaData data = null;
try {
data = (MetaData) metaData.clone();
data.setDatabaseName(Constants.HSSYSDB);
} catch (CloneNotSupportedException e) {
logger.warn("", e);
return;
}
String driver = dbConfig.getDriver();
String url = Utils.replaceParams(dbConfig.getDbURL(), data);
Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = getConnection(driver, url, prop);
String insertDb = Utils.replaceParams(dbConfig.getInsertSysDb(), data);
stmt = conn.prepareStatement(insertDb);
stmt.setString(1, dbName);
stmt.setString(2, quality);
stmt.setInt(3, type);
stmt.execute();
} catch (ClassNotFoundException e) {
logger.warn("", e);
} catch (SQLException e) {
logger.warn("", e);
} finally {
freeConnection(stmt, conn);
}
}
use of java.sql.PreparedStatement in project translationstudio8 by heartsome.
the class SystemDBOperator method removeSysDb.
/**
* 删除系统库中保存的指定的数据库
* @param dbName
* @throws SQLException
*/
public void removeSysDb(String dbName) throws SQLException {
Connection conn = null;
PreparedStatement pstmt = null;
String driver = dbConfig.getDriver();
metaData.setDatabaseName(Constants.HSSYSDB);
String url = Utils.replaceParams(dbConfig.getDbURL(), metaData);
Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), metaData);
// 删除系统表中的数据
prop = Utils.replaceParams(dbConfig.getConfigProperty(), metaData);
try {
conn = getConnection(driver, url, prop);
String removeDb = dbConfig.getRemoveSysDb();
pstmt = conn.prepareStatement(removeDb);
pstmt.setString(1, dbName);
pstmt.execute();
} catch (ClassNotFoundException e) {
logger.warn("", e);
} finally {
freeConnection(pstmt, conn);
}
}
use of java.sql.PreparedStatement in project translationstudio8 by heartsome.
the class DBOperator method insertTMXExtra.
/**
* 将数据写入到Extra表中
* @param type
* @param eleName
* @param eleContent
* @param pName
* @param pId
* @throws SQLException
* ;
*/
public void insertTMXExtra(String type, String eleName, String eleContent, String pName, String pId) throws SQLException {
PreparedStatement stmt = null;
try {
String sql = dbConfig.getOperateDbSQL("insert-tmxextra");
stmt = conn.prepareStatement(sql);
int i = 1;
stmt.setString(i++, pName);
stmt.setInt(i++, Integer.parseInt(pId));
stmt.setString(i++, type);
stmt.setString(i++, eleName);
stmt.setString(i++, eleContent);
stmt.executeUpdate();
} finally {
if (stmt != null) {
stmt.close();
}
}
}
use of java.sql.PreparedStatement in project translationstudio8 by heartsome.
the class DBOperator method getTermEntryContentByPk.
/**
* 通过BTERMENTRY表的主键获取该TermEntry的内容
* @param termEntrypk
* @return TermEntry节点的完整内容;
* @throws SQLException
*/
public String getTermEntryContentByPk(Integer termEntrypk) throws SQLException {
String result = "";
PreparedStatement stmt = null;
ResultSet rs = null;
try {
String sql = dbConfig.getOperateDbSQL("getTermEntryContent-bypk");
stmt = conn.prepareStatement(sql);
stmt.setInt(1, termEntrypk);
rs = stmt.executeQuery();
if (rs.next()) {
return result = rs.getString(1);
}
} finally {
if (stmt != null) {
stmt.close();
}
if (rs != null) {
rs.close();
}
}
return result;
}
use of java.sql.PreparedStatement in project translationstudio8 by heartsome.
the class DBOperator method getConcordanceSearchResult.
// TODO ======================匹配相关(结束) ======================//
/**
* 执行相关搜索
* @param strSearch
* 搜索文本
* @param isCaseSensitive
* 是否区分大小写
* @param isApplyRegular
* 是否使用正则表达式
* @param isIgnoreMark
* 是否忽略标记
* @param strLang
* 源语言
* @param lstLangs
* 语言集合(包括源语言)
* @param startIndex
* 开始行号
* @param intMax
* 最大查找结果数
* @return ;
*/
public List<ConcordanceBean> getConcordanceSearchResult(String strSearch, boolean isCaseSensitive, boolean isApplyRegular, boolean isIgnoreMark, String strLang, List<String> lstLangs, List<Integer> subList) {
String sql = getTMSearchSql(dbConfig.getOperateDbSQL("search-Corcondance"), isIgnoreMark, lstLangs, subList);
if (sql == null) {
return null;
}
List<ConcordanceBean> lstConcordance = new ArrayList<ConcordanceBean>();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
ArrayList<Integer> lstTuId = new ArrayList<Integer>();
while (rs.next()) {
Integer tuId = rs.getInt("TUID");
if (lstTuId.contains(tuId)) {
ConcordanceBean bean = lstConcordance.get(lstTuId.indexOf(tuId));
LanguageTMX lang = new LanguageTMX();
lang.setLanguageCode(rs.getString("LANG"));
lang.setText(rs.getString("TMTEXT"));
bean.getLanguageList().add(lang);
} else {
lstTuId.add(tuId);
ConcordanceBean bean = new ConcordanceBean();
bean.setId(tuId);
bean.setCreationId(rs.getString("CREATIONID"));
String creationDate = "";
Timestamp tempCreationDate = rs.getTimestamp("CREATIONDATE");
if (tempCreationDate != null) {
creationDate = DateUtils.formatLongTime(tempCreationDate.getTime(), "yyyy-MM-dd HH:mm:ss");
}
bean.setCreationDate(creationDate);
bean.setChangeId(rs.getString("CHANGEID"));
String changeDate = "";
Timestamp tempChangeDate = rs.getTimestamp("CHANGEDATE");
if (tempChangeDate != null) {
changeDate = DateUtils.formatLongTime(tempChangeDate.getTime(), "yyyy-MM-dd HH:mm:ss");
}
bean.setChangeDate(changeDate);
bean.setBlnIsFlag(rs.getString("MPPKID") != null);
List<LanguageTMX> lstLang = new ArrayList<LanguageTMX>();
LanguageTMX lang = new LanguageTMX();
lang.setLanguageCode(rs.getString("LANG"));
lang.setText(rs.getString("TMTEXT"));
lstLang.add(lang);
bean.setLanguageList(lstLang);
bean.setAttributeList(getTuMprops(tuId, "TU"));
lstConcordance.add(bean);
}
}
} catch (SQLException e) {
LOGGER.error("", e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
LOGGER.error("", e);
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
return lstConcordance;
}
Aggregations