java.sql.SQLException: Unable to connect to any hosts due to exception: java.lang.ArrayIndexOutOfBoundsException
Posted by: Shamir Pondiong
Date: April 23, 2010 04:14PM

I guys... I am a newbie in programming with Java, MySQL and Struts... I am encountering this problem... Can you guys help me pinpoint the error?

the details of my program are listed below...

===========================

my struts-config.xml is:

<struts-config>
<!-- ========== DataSource Definitions =================================== -->
<data-sources>
<data-source key="phonebook" type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="description" value="Phone Book Collection"/>
<set-property property="driverClassName" value="com.mysql.jdbc.Driver"/>
<set-property property="username" value="pbook"/>
<set-property property="password" value="pbook"/>
<set-property property="url" value="jdbc:mysql://localhost:3306/phonebook" />
<set-property property="maxActive" value="10" />
<set-property property="defaultAutoCommit" value="false" />
<set-property property="defaultReadOnly" value="false" />
</data-source>
</data-sources>

<!-- ========== Form Bean Definitions =================================== -->
<form-beans>
<form-bean name="loginForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="userName" type="java.lang.String" initial=""/>
<form-property name="passWord" type="java.lang.String" initial=""/>
</form-bean>
</form-beans>

<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<action path="/index"
type="org.phonebook.my.action.LoginAction"
name="loginForm"
scope="request"
input="/index.jsp"
validate="true">
<forward name="failure" path="/index.jsp"/>
<forward name="success" path="/user/index.jsp"/>
</action>
</action-mappings>

<!-- ========== Message Resources Definitions =========================== -->
<message-resources null="false" parameter="ApplicationResources"/>

<!-- ========== Plugin Definitions =========================== -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
<!--plug-in className="dummies.struts.music.StartupManager" /-->
</struts-config>




My code to connect to the MySQL server is:

public DBTest query(String uName, String pWord) throws DAOException {
UserBean user = null;
Connection conn = null;
ResultSet rs = null;
PreparedStatement ps = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/phonebook", "pbook", "pbook");
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM phonebook.users WHERE username='" + uName + "' AND password='" + pWord + "'");

} catch (ClassNotFoundException ex) {
ex.printStackTrace();
throw new DAOException(ex.getMessage());
} catch (SQLException ex) {
ex.printStackTrace();
throw new DAOException(ex.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException ex) {
log.error("Error in closing ResultSet.");
throw new DAOException("error.db.sql");
}
try {
if (ps != null) {
ps.close();
}
} catch (SQLException ex) {
log.error("Error in closing PreparedStatement.");
throw new DAOException("error.db.sql");
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
log.error("Error in closing Connection.");
throw new DAOException("error.db.sql");
}
}
return user;
}



and when I connect to MySQL (MySQL Server 5.1), I get this error:



java.sql.SQLException: Unable to connect to any hosts due to exception: java.lang.ArrayIndexOutOfBoundsException: 41
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1797)
at com.mysql.jdbc.Connection.<init>(Connection.java:562)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:361)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)

===============================

I'm using Apache Tomcat 5.5, Struts 1.2, MySQL server 5.1, Java v.1.5 and mysql-connector-java-3.0.9-stable-bin.jar

Thank you in advance

Options: ReplyQuote




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.