Search in sources :

Example 76 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class TMDatabaseImpl method insertBAttribute.

/**
	 * 写BAttribute的内容
	 * @param attrs
	 * @param parentName
	 * @param parentId
	 * @throws SQLException
	 *             ;
	 */
public void insertBAttribute(Map<String, String> attrs, String parentName, int parentId) throws SQLException {
    if (attrs != null) {
        PreparedStatement stmt = null;
        String sql = dbConfig.getOperateDbSQL("insert-battribute");
        Iterator<Entry<String, String>> iter = attrs.entrySet().iterator();
        try {
            while (iter.hasNext()) {
                Entry<String, String> entry = iter.next();
                String attrName = entry.getKey();
                String attrValue = entry.getValue();
                stmt = conn.prepareStatement(sql);
                stmt.setInt(1, parentId);
                stmt.setString(2, attrName);
                stmt.setString(3, attrValue);
                stmt.setString(4, parentName);
                stmt.addBatch();
            }
            stmt.executeBatch();
            stmt.clearBatch();
        } finally {
            if (stmt != null) {
                stmt.close();
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) OraclePreparedStatement(oracle.jdbc.OraclePreparedStatement) PreparedStatement(java.sql.PreparedStatement)

Example 77 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class TMDatabaseImpl method insertTMXNote.

/**
	 * 将数据插入TMXNOTES表
	 * @param params
	 *            ;
	 * @throws SQLException
	 */
public void insertTMXNote(Hashtable<String, String> params) throws SQLException {
    PreparedStatement stmt = null;
    try {
        String sql = dbConfig.getOperateDbSQL("insert-tmxnotes");
        stmt = conn.prepareStatement(sql);
        int i = 1;
        stmt.setString(i++, params.get("PARENTNAME"));
        stmt.setInt(i++, Integer.parseInt(params.get("PARENTID")));
        stmt.setString(i++, params.get("CONTENT"));
        stmt.setString(i++, params.get("CREATIONID"));
        stmt.setString(i++, params.get("CREATIONDATE"));
        stmt.setString(i++, params.get("CHANGEID"));
        stmt.setString(i++, params.get("CHANGEDATE"));
        stmt.setString(i++, params.get("ENCODING"));
        stmt.setString(i++, params.get("LANG"));
        stmt.executeUpdate();
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}
Also used : OraclePreparedStatement(oracle.jdbc.OraclePreparedStatement) PreparedStatement(java.sql.PreparedStatement)

Example 78 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class OperateSystemDBImpl method removeSysDb.

/**
	 * 删除系统库中保存的指定的数据库
	 * @param dbName
	 * @throws SQLException
	 */
public void removeSysDb(String dbName) throws SQLException {
    PreparedStatement pstmt = null;
    String driver = dbConfig.getDriver();
    metaData.setDatabaseName(Constants.HSSYSDB);
    String url = Utils.replaceParams(dbConfig.getDbURL(), metaData);
    url = url.replace("__FILE_SEPARATOR__", File.separator);
    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);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties)

Example 79 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class OperateSystemDBImpl method getSysDbNames.

/**
	 * 得到系统库中的存储的数据库名称
	 * @return
	 * @throws SQLException
	 */
public List<String> getSysDbNames(int type) {
    MetaData data = null;
    try {
        data = (MetaData) metaData.clone();
        data.setDatabaseName(Constants.HSSYSDB);
    } catch (CloneNotSupportedException e) {
        LOGGER.warn("", e);
        return null;
    }
    String driver = dbConfig.getDriver();
    String url = Utils.replaceParams(dbConfig.getDbURL(), data);
    url = url.replace("__FILE_SEPARATOR__", File.separator);
    Properties prop = Utils.replaceParams(dbConfig.getConfigProperty(), data);
    PreparedStatement stmt = null;
    ResultSet rs = null;
    List<String> result = new ArrayList<String>();
    try {
        conn = getConnection(driver, url, prop);
        String sql = dbConfig.getSysDbList();
        stmt = conn.prepareStatement(sql);
        stmt.setInt(1, type);
        rs = stmt.executeQuery();
        while (rs.next()) {
            result.add(rs.getString("DBNAME"));
        }
    } catch (ClassNotFoundException e) {
        LOGGER.warn("", e);
    } catch (SQLException e) {
        LOGGER.warn("", e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOGGER.warn("", e);
            }
        }
        freeConnection(stmt, conn);
    }
    return result;
}
Also used : SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties)

Example 80 with PreparedStatement

use of java.sql.PreparedStatement in project translationstudio8 by heartsome.

the class TMDatabaseImpl method findTrems.

private void findTrems(String srcPureText, String srcLang, String tarLang, Vector<Hashtable<String, String>> result) throws SQLException {
    Vector<Hashtable<String, String>> terms = new Vector<Hashtable<String, String>>();
    // 构建SQL
    String getTermSql = dbConfig.getOperateDbSQL("getTerm");
    PreparedStatement stmt = conn.prepareStatement(getTermSql);
    stmt.setString(1, tarLang);
    stmt.setString(2, srcLang + "," + tarLang);
    stmt.setString(3, tarLang + "," + srcLang);
    stmt.setString(4, srcLang);
    stmt.setString(5, srcPureText);
    /*
		 * SELECT A.TPKID, A.PURE, B.PURE FROM TEXTDATA A LEFT JOIN TEXTDATA B ON A.GROUPID=B.GROUPID AND B.LANG=? AND
		 * B.TYPE='B' WHERE A.TYPE='B' AND A.LANG=? AND LOCATE(A.PURE, ?) AND B.PURE IS NOT NULL;
		 */
    ResultSet rs = stmt.executeQuery();
    TO: while (rs.next()) {
        String tuid = rs.getString(1);
        String srcWord = rs.getString(2);
        String tgtWord = rs.getString(3);
        String property = rs.getString(4);
        for (Hashtable<String, String> temp : result) {
            String _srcWord = temp.get("srcWord");
            String _tgtWord = temp.get("tgtWord");
            if (srcWord.equals(_srcWord) && tgtWord.equals(_tgtWord)) {
                continue TO;
            }
        }
        Hashtable<String, String> tu = new Hashtable<String, String>();
        tu.put("tuid", tuid);
        tu.put("srcLang", srcLang);
        tu.put("srcWord", srcWord);
        tu.put("tgtLang", tarLang);
        tu.put("tgtWord", tgtWord);
        tu.put("property", property == null ? "" : property);
        terms.add(tu);
    }
    rs.close();
    stmt.close();
    result.addAll(terms);
}
Also used : Hashtable(java.util.Hashtable) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Vector(java.util.Vector)

Aggregations

PreparedStatement (java.sql.PreparedStatement)6623 ResultSet (java.sql.ResultSet)4065 SQLException (java.sql.SQLException)3538 Connection (java.sql.Connection)2806 Test (org.junit.Test)1103 ArrayList (java.util.ArrayList)963 Properties (java.util.Properties)743 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)345 Statement (java.sql.Statement)273 Timestamp (java.sql.Timestamp)260 DatabaseException (net.jforum.exceptions.DatabaseException)254 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)251 HashMap (java.util.HashMap)209 BigDecimal (java.math.BigDecimal)207 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)174 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)165 List (java.util.List)150 IOException (java.io.IOException)145 Date (java.util.Date)133 Date (java.sql.Date)126