java.sql.SQLException:ORA-00928:缺少SELECT關(guān)鍵字。使用JDBC將記錄插入數(shù)據(jù)庫時
我可以發(fā)現(xiàn)兩個問題:
不需要在列名周圍使用單引號。但是您可以將其用雙引號引起來。如果對列名或表名使用保留關(guān)鍵字,則很有必要。在這里DATE。您需要一個空格VALUES。因此,您需要更改insertStmt為以下內(nèi)容:
String insertStmt = 'INSERT into ' + 'MY_TABLE(RECORD_TYPE, FILE_TYPE, 'DATE', BATCH_NO, RECORD_COUNT) ' + 'VALUES(?, ?, ?, ?, ?);';解決方法
當(dāng)我嘗試向數(shù)據(jù)庫中插入一些行時出現(xiàn)錯誤。所以這是代碼
try { String insertStmt = 'INSERT into ' +'MY_TABLE(’RECORD_TYPE’,’FILE_TYPE’,’DATE’,’BATCH_NO’,’RECORD_COUNT’)' +'VALUES(?,?,?);'; PreparedStatement pstmt = super.con.prepareStatement(insertStmt); pstmt.setString(1,input[0]); pstmt.setString(2,input[1]); pstmt.setString(3,input[2]); pstmt.setString(4,input[3]); pstmt.setString(5,input[4]); System.out.println('Insert rows : ' + pstmt.executeUpdate());} catch (SQLException sqle) { System.out.println(sqle.getMessage()); sqle.printStackTrace();} catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace();} finally { con.close();}
并且數(shù)據(jù)庫上的所有內(nèi)容均為varchar類型,請仔細(xì)檢查各列(它們都是相同的名稱),將列名中的引號引起來(相同的結(jié)果)不會成功。要添加它,錯誤消息不是很有幫助。
任何建議,將不勝感激。
相關(guān)文章:
1. java - 安卓電視盒子取得了root權(quán)限但是不能安裝第三方應(yīng)用,請問該怎么辦?2. 在MySQL中新增字段時,報錯??3. 老哥們求助啊4. python - 模擬滑動驗證碼,有源碼,求解5. javascript - js 寫一個正則 提取文本中的數(shù)據(jù)6. css3 - 請問一下在移動端CSS布局布局中通常需要用到哪些元素,屬性?7. npm鏡像站全新上線8. javascript - vue-router怎么不能實現(xiàn)跳轉(zhuǎn)呢9. javascript - [WDS] Disconnected! 一直重復(fù)出現(xiàn)。10. html5 - angularjs中外部模版加載無法使用
