• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Tomcat6, MySQL and a Servlet - Problem: NameAlreadyBoundException  RSS feed

 
Greenhorn
Posts: 2
Debian MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A nice Hello to everybody here!

I tried for days now, to enable a connection to mysql with a Servlet on Tomcat 6.
What I already have:
Debian Squeeze, Apache2, Tomcat 6, MySQL example-database with
an user "peter", and his password "something" and
a Database called "datenbank1" with a table called "personen" and some textdata in it.
mysql is bound to 127.0.0.1 (localhost) and the port 3306

I already copied mysql-connector-java-5.1.22-bin.jar to ~TOMCAT/lib
and did there this:
chmod 777 mysql-connector-java-5.1.22-bin.jar
chown root mysql-connector-java-5.1.22-bin.jar
chgrp root mysql-connector-java-5.1.22-bin.jar

then I installed the mysql-java with apt-get
and applied ini /etc/tomcat6/catalina.properties
common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,/var/lib/tomcat6/common/classes,/var/lib/tomcat6/common/*.jar,/usr/share/java/mysql.jar

restarted tomcat
--------------------- my servlet :
to make a war-file i set up the folder:
- - sqltest
index.html
- - - META-INF
context.xml
- - - WEB-INF
web.xml
- - - - - classes
EinTestServlet.java
EinTestServlet.class

My context.xml:


<Context>
<Resource name="jdbc/meinedb" auth="Container" type="javax.sql.DataSource"
maxActive="50" maxIdle="30" maxWait="10000"
username="peter" password="something"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/datenbank1"></Resource>
</Context>


----------------------

My web.xml


<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<resource-ref>
<description>DB Connection</description>
<res-ref-name>/jdbc/meinedb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

<servlet>
<servlet-name>EinTestServlet</servlet-name>
<description>Zeigt personen aus datenbank1 an</description>
<servlet-class>EinTestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EinTestServlet</servlet-name>
<url-pattern>/servlets/EinTestServlet</url-pattern>
</servlet-mapping>
</web-app>


----------------------

My Servlet "EinTestServlet.java"

----------------------

i compile the java with:
javac -cp /usr/share/tomcat6/lib/servlet-api.jar EinTestServlet.java
ok!

i build the war-file with ../sqltest/jar -cvf meintest.war .
ok!

I deploy the war-file with the tomcat-manager and I could run it.
but there are Errors: (tomcat..logs/catalina.out)


17.10.2012 13:33:07 org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive sqlbsp.war
17.10.2012 13:33:07 org.apache.catalina.core.NamingContextListener addResource
SCHWERWIEGEND: Failed to bind object: javax.naming.NameAlreadyBoundException: Name meinedb is already bound in this Context
java.sql.SQLException: Invalid value for getInt() - 'B7C5KKLJ901'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2762)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2850)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:275)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:275)
at EinTestServlet.doGet(EinTestServlet.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:636)
17.10.2012 13:34:27 org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/sqlbsp]



Please, can someone find the error in my source?
i try for some days now to get the stuff done, i tried already different konds of context and web files and a lot of codes - nothing seems to run. i dont see the error in my code.



 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.sql.SQLException: Invalid value for getInt() - 'B7C5KKLJ901' ....

check here what is value you are trying to supply....

or can you post what the values are you passing.


 
Florian Muellerer
Greenhorn
Posts: 2
Debian MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Mr. Kumar!
That was the right Advice.

I changed the code in the while-loop as followed:



And it works!

Because, the ID seems not to be a int-Number, its a mixed type and the rest was also able to be read as a String.
I thought all the time, there must something wrong with the Connection!

Thanks for this advice.
;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!