> The connection URL looks wrong as well. It should be
> something like:
>
> "jdbc:mysql://localhost/neo"
> > > hello friends
> > > i have just touched jsp programming and i m having trouble connecting
[quoted text clipped - 39 lines]
> you
> thanks
It has to be "jdbc:mysql://localhost/neo" not //localhostneo.
Do this code:
Driver d = new com.mysql.jdbc.Driver();
System.out.println("Will the mysql driver accept the URL '" + dbURL +
"'? " + d.acceptsURL(dbURL) );
When you get it to return true, then you have a better chance of
connecting...
Joe
>> Unless you want to use container managed connection pool you
>> should put the jar file in your web apps WEB-INF/lib.
>
> well i have put it the jar file there too.
Not too. Only there.
You should not put jar files all over the system.
>> The connection URL looks wrong as well. It should be
>> something like:
[quoted text clipped - 3 lines]
> well i thought that you have to provide the location of the database
> in this place "jdbc:mysql://localhost/neo"
No. You connect to localhost (on port 3306) and select database
neo. The MySQL servers knows where it is actually stored.
> though i have tried putting database as //localhostneo also
> but this didnt work too
Unless you have a host called localhostneo then it will not work.
> please suggest something
> or if you could give me a working example it would be very kind of
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost/Test", "", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM T1");
...
works for me.
Arne
naveen - 09 Apr 2008 03:05 GMT
> > though i have tried putting database as //localhostneo also
> > but this didnt work too
well i am soory ..my mistake i meant //localhost/neo
> <%
> Class.forName("com.mysql.jdbc.Driver");
[quoted text clipped - 5 lines]
>
> works for me.
well i have used:
________________________________________________________
...
<%
String varSql = request.getParameter("sql");
if (varSql == null) {
varSql = "";
}
varSql = java.net.URLDecoder.decode(varSql).trim();
%>
...
<%
String dbURL="jdbc:mysql://localhost/neo";
String username="root";
String passwd="abc";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(dbURL,username,passwd);
Statement stat=null;
try{
stat=conn.createStatement();
if(varSql.length() !=0 ){
%>
<pre> <%= varSql %> </pre>
<%
if (stat.execute(varSql)) {
java.sql.ResultSet rs = stat.getResultSet();
try {
java.sql.ResultSetMetaData metaData = rs.getMetaData();
int colCount =metaData.getColumnCount();
%>
...
________________________________________________________
now i must be making a mistake somewhere since the browser shows this:
_____________________________________________________
An Exception was caught while connecting to the database.
java.sql.SQLException: Communication link failure:
java.io.IOException, underlying cause: Unexpected end of input stream
** BEGIN NESTED EXCEPTION **
java.io.IOException
MESSAGE: Unexpected end of input stream
STACKTRACE:
java.io.IOException: Unexpected end of input stream
at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:1096)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:626)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1562)
at com.mysql.jdbc.Connection.(Connection.java:491)
at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:
346)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.apache.jsp.HelloMysql_jsp._jspService(HelloMysql_jsp.java:98)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
393)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:
320)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
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:
230)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
104)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
261)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
844)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
447)
at java.lang.Thread.run(Unknown Source)
____________________________________________________
what should i do about this?
please help
Arne Vajhøj - 09 Apr 2008 03:24 GMT
>>> though i have tried putting database as //localhostneo also
>>> but this didnt work too
>
> well i am soory ..my mistake i meant //localhost/neo
As a general rule: copy paste when you post to avoid typos.
> <%
> String varSql = request.getParameter("sql");
[quoted text clipped - 14 lines]
> try{
> stat=conn.createStatement();
> java.sql.SQLException: Communication link failure:
> java.io.IOException, underlying cause: Unexpected end of input stream
[quoted text clipped - 19 lines]
> at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
You have loaded the driver OK, you have established a TCP connection
to the server OK, but the JDBC driver and the MySQL server will not
talk to each other. It look like the MySQL server closes the connection.
Check that the JDBC driver you are using are newer than the MySQL
server version you are using.
Check in the MySQL side for errors.
Arne
naveen - 09 Apr 2008 14:02 GMT
> You have loaded the driver OK, you have established a TCP connection
> to the server OK, but the JDBC driver and the MySQL server will not
> talk to each other. It look like the MySQL server closes the connection.
>
> Check that the JDBC driver you are using are newer than the MySQL
> server version you are using.
i am using |mysql-connector-java-5.1.6| connector
and |mysql-5.0.51a-win32| mysql database
i think these are latest versions and probably should comply with each
other.
> Check in the MySQL side for errors.
how do i do that ? please elucidate
other than this, i tried connecting to mysql
using jndi as described in the apache tomcat documentation
but it's example jsp uses jstl
the test.jsp is of form:
________________________________
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<sql:query var="rs" dataSource="jdbc/TestDB">
select id, foo, bar from testdata
</sql:query>
<html>
<head>
<title>DB Test</title>
</head>
<body>
<h2>Results</h2>
<c:forEach var="row" items="${rs.rows}">
Foo ${row.foo}<br/>
Bar ${row.bar}<br/>
</c:forEach>
</body>
</html>
____________________________________________
the described jndi example works but i dont know jstl
and i need to use simple jsp coding
now if anyone would do me a favor by converting the test.jsp as shown
to a simple jsp (i.e. without using the jstl) then my problem would
stand
solved for now
somebody please help
Lew - 10 Apr 2008 00:52 GMT
Arne advised (and naveen neglected to attribute):
>> Check in the MySQL side for errors.
> how do i [sic] do that ? please elucidate
www.mysql.com
> the described jndi [sic] example works but i [sic] dont know jstl [sic]
<http://java.sun.com/javaee/5/docs/tutorial/doc/bnakc.html>
> now if anyone would do me a favor by converting the test.jsp as shown
> to a simple jsp (i.e. without using the jstl) then my problem would
> stand solved for now
That's funny!

Signature
Lew
naveen - 10 Apr 2008 19:56 GMT
> > now if anyone would do me a favor by converting the test.jsp as shown
> > to a simple jsp (i.e. without using the jstl) then my problem would
> > stand solved for now
>
> That's funny!
man! u really have got a big funny bone :-)
however thanks guys at last i made the cut.
though through jndi
thanks ..again