我知道第一個是同步的,後面的一個是非同步的,響應時間更快。StringBuffer或StringBuilder用於我的查詢
我使用StringBuffer
來追加SQL查詢。轉移到StringBuilder
會使它更快(我的問題特別是關於SQL)?
建議圍繞SQl查詢追加使用StringBuilder
嗎?
我當前的代碼
public boolean saveData (Connection conn,MyObject) throws SQLException {
..
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
StringBuffer sSubQry = new StringBuffer();
sSubQry.append (" select ID, STATEID, TYPEID, LANGID, SEQ, ");
sSubQry.append (" SECTIONSEQ, CODE, NAME, INPUTNAME, ");
sSubQry.append (" .., .., ..,");
sSubQry.append (" .., .., ..,");
..
..
pstmt = conn.prepareStatement(sSubQry.toString());
rs = pstmt.executeQuery();
while (rs.next())
{
..
}
}
,將其傳輸到StringBuilder
有任何+ve
或-ve
效果
public boolean saveData (Connection conn,MyObject) throws SQLException {
..
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
StringBuilder sSubQry = new StringBuilder();
sSubQry.append (" select ID, STATEID, TYPEID, LANGID, SEQ, ");
sSubQry.append (" SECTIONSEQ, CODE, NAME, INPUTNAME, ");
sSubQry.append (" .., .., ..,");
sSubQry.append (" .., .., ..,");
..
pstmt = conn.prepareStatement(sSubQry.toString());
rs = pstmt.executeQuery();
while (rs.next())
{
..
}
}
建議不要使用SQL查詢追加。你爲什麼需要這樣做? – Siyual
@Siyual我的查詢太長了 –
檢查['PreparedStatement'](http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html) – sam