我想在java應用程序中運行SQLQuery。 sqlquery連接兩個數據庫(不在同一臺服務器上)。難道更正一下,我在這裏做什麼:用mysql查詢在Java中加入兩個數據庫?
公共功能有:
private DatabaseData externaldb = new DatabaseData("com.mysql.jdbc.Driver",
"...", "...", "...");
private DatabaseData localdb = new DatabaseData("com.mysql.jdbc.Driver",
"...", "...", "...");
private Connection externalconnection = null;
private Connection localconnection = null;
function(externalconnection, c_id, u_d);
調用的函數是:
private int function(Connection externalconnection, String c_Id, String u_Id)
throws SQLException{
String query ="SELECT A.v_id, COUNT(I.v_id) AS v_count "
+ "FROM externaldb.video_interaction I"
+ " INNER JOIN localdb.video_additional A ON A.v_id = I.v_id"
+ " WHERE I.c_id='" + c_id + "' AND I.user'" + u_Id + "';";
Statement stmt = externaldb.createStatement();
ResultSet rs = stmt.executeQuery(query);
int counter = 0;
if (rs.next()){
counter = rs.getInt("video_count");
}
return counter;
}
謝謝!
有你嘗試了上面的代碼??你遇到了什麼問題..與我們無法幫助你的那些細節分享 – Akshay
謝謝。我們仍在準備服務器。這就是爲什麼我目前沒有反饋意見。 –
一旦遇到問題就會回來。否則我們也可以推測 – XtremeBaumer