Re: incorrect information ?
Posted by:
kostya kote
Date: September 19, 2005 08:35AM
ok. this is my code written as UnitTest
public class testFailover extends TestCase {
private String driver;
private Properties prop;
private String url;
private Connection conn = null;
public void loopOp() throws SQLException {
try {
conn = getConnection();
// conn.setAutoCommit(false);
while (true) {
try {
doBusinessOp();
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
} finally {
conn.close();
}
}
public void doBusinessOp() throws SQLException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
//
String query = "SELECT * FROM mysql.user";
stmt = conn.prepareStatement(query);
rs = stmt.executeQuery(query);
int i = 0;
while (rs.next()) {
Config.logger.info("Host" + (i++) + ":" + rs.getString("Host"));
}
rs.close(); rs = null;
stmt.close(); stmt = null;
conn.commit();
Config.logger.info("transaction completed!");
} catch (Exception sqlEx) {
Config.logger.info("Error:"+sqlEx.getMessage());
}
}
private Connection getConnection() throws SQLException {
Connection c = null;
prop = new Properties();
prop.setProperty("user", "root");
prop.setProperty("password", "");
prop.setProperty("autoReconnect", "true");
// prop.setProperty("queriesBeforeRetryMaster", "10");
prop.setProperty("secondsBeforeRetryMaster", "10");
prop.setProperty("roundRobinLoadBalance", "false");
// prop.setProperty("failOverReadOnly", "false");
url = "jdbc:mysql://10.50.1.7, 10.50.1.8/company_db";
driver = "org.gjt.mm.mysql.Driver";
try {
Class.forName(driver); // init
} catch (ClassNotFoundException e) {
Config.logger.error("No class found for driver = '" + driver + "'. Exception: " + e);
throw new RuntimeException(e); // raise exeption
}
c = DriverManager.getConnection(url, prop);
return c;
}
}
as I said, I have 2 sql nodes resided at 10.50.1.7 and 10.50.1.8 correspondingly.
when I broke connection with a frist sql node I havent recoonect to second as mentioned in documentation and other sources. If client application coonects only to one server and this server is down that we have single point of failure. isnt it ?
Edited 1 time(s). Last edit at 09/19/2005 08:44AM by kostya kote.
Subject
Views
Written By
Posted
4666
September 16, 2005 11:14AM
1968
September 19, 2005 04:26AM
1943
September 19, 2005 06:35AM
1891
September 19, 2005 06:48AM
1866
September 19, 2005 06:53AM
1812
September 19, 2005 07:08AM
1704
September 19, 2005 07:13AM
1909
September 19, 2005 07:42AM
1804
September 19, 2005 07:52AM
1639
September 19, 2005 08:04AM
1738
September 19, 2005 08:24AM
Re: incorrect information ?
1753
September 19, 2005 08:35AM
1750
September 19, 2005 09:42AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.