如何從selenium webdriver從sql數據庫中獲取數據?如何從selenium webdriver的sql數據庫中獲取數據?
我想連接硒的webdriver和SQL數據庫,並且需要從數據庫中獲取價值和硒TestNG的框架使用。 任何人都可以爲我提供正確的解決方案。
如何從selenium webdriver從sql數據庫中獲取數據?如何從selenium webdriver的sql數據庫中獲取數據?
我想連接硒的webdriver和SQL數據庫,並且需要從數據庫中獲取價值和硒TestNG的框架使用。 任何人都可以爲我提供正確的解決方案。
首先,你需要使用以下命令,讓與數據庫連接,
的DriverManager.getConnection(數據庫的URL,「用戶名」,「密碼」)
中獲取價值,使用下面的命令
ResultSet result = stmt.executeQuery(select * from tablename;);
當然,我會做的,並檢查.. –
如果一切正常,你可以批准答案:) – rhea
您需要實現DB連接器幫手連接,執行查詢和關閉數據庫連接。比你可以在你的測試中使用查詢結果之後。
數據庫連接器依賴於DB型(你需要使用指定DB驅動程序)。 如下因素的Java methodis與SQL Server驅動程序圖示連接:不是關閉連接
public void executeQuery(String query) {
con = this.getConnection();
if (con != null) {
Statement st = null;
try {
st = con.createStatement();
st.executeQuery(query);
} catch (SQLException e) {}
}
this.closeConnection();
}
:
public void closeConnection() {
try {
if (con != null)
con.close();
con = null;
} catch (Exception e) {}
}
謝謝....我將與這些檢查..... –
參見:
和執行查詢[我如何做X?( https://meta.stackoverflow.com/questions/253069/whats-the-appropriate-new-current-close-reason-for-how-do-i-do-x)對SO的期望是,用戶問一個研究不僅要回答他們自己的追求離子,但也分享研究,代碼嘗試和結果。這表明你已經花時間去嘗試幫助自己,它使我們避免重申明顯的答案,最重要的是它可以幫助你得到更具體和相關的答案!參見:[提問] – JeffC