participate


JavaServer Pages (JSP) and JSTL - Can't Find MySQL driver in JSP
<<   Back to Forum  |   Give us Feedback
This topic has 26 replies on 2 pages.    « Previous | 1 | 2 |
Andrew-C
Posts:8
Registered: 9/25/03
Re: Can't Find MySQL driver in JSP   
Mar 22, 2004 3:55 PM (reply 15 of 26)  (In reply to #4 )

 
I had exactly the same problem as the original poster. i.e. a bit of JSP like this:

<%@ taglib uri='/taglib-sql' prefix='sql' %>
<%@ taglib uri='/taglib-core' prefix='c' %>

<sql:setDataSource
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/helpdesk"
user="root"
password="12345"
var="hdesk" />

<sql:query var="tickets" dataSource="${hdesk}">
SELECT FROM tblTicket;
</sql:query>

caused a "no suitable driver" error

I found that this problem simply went away by removing the 'var' attribute on the sql:setDataSource tag and the corresponding 'dataSource' attribute on the sql:query tag to give the following:

<%@ taglib uri='/taglib-sql' prefix='sql' %>
<%@ taglib uri='/taglib-core' prefix='c' %>

<sql:setDataSource
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/helpdesk"
user="root"
password="12345" />

<sql:query var="tickets" >
SELECT
FROM tblTicket;
</sql:query>

I have no idea why; I have seen lots of posts from people with the same problem though and no solutions; maybe there is a bug somewhere?!?
 
mwoinoski
Posts:126
Registered: 31/08/97
Re: Can't Find MySQL driver in JSP   
Dec 4, 2004 4:01 PM (reply 16 of 26)  (In reply to original post )

 
I had the same problem and solved it by moving the mysql-connector-java-*.jar file to TOMCAT_HOME\common\endorsed.

Mike
 
Bunker
Posts:6
Registered: 1/13/05
Re: Can't Find MySQL driver in JSP   
Jan 14, 2005 5:15 PM (reply 17 of 26)  (In reply to #16 )

 
I have the same problems, too!
I use Windows 2000, Tcomcat 5, MySQL 4.1.7 and JSTL 1.1. When my JSP tried to connect to the database, I got these error messages:
javax.servlet.ServletException: Unable to get connection, DataSource invalid: "No suitable driver"
I saw lots of threads about this "no suitable driver" in the forums, but it samed no one could solve this problem....
My JSP is like this and actually I copy them from the book "Beginning JSP 2: From Novice to Professional"...

 <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql_rt" %>
 
<sql:setDataSource var="datasource" driver="com.mysql.jdbc.Driver"
                    url="jdbc:mysql://localhost:3306/publish"
                   user="publish" password="publish"/>
 
<sql:query var="books" dataSource="$(datasource)">
	select id, title, price from book;
</sql:query>

Can any one have solved this trouble help me, or us? Thanks a lot.
Roger
 
JOKe
Posts:123
Registered: 11/26/04
Re: Can't Find MySQL driver in JSP   
Apr 28, 2005 1:53 AM (reply 18 of 26)  (In reply to #17 )

 
i have the same problem the problem was in naming support ... JNDI was not checked from the tomcat context menu .. :)

so the steps are :
create context and make naming=true
create DataSource for this context in the tomcat/admin menu
and the source you give works
 
tbeernot
Posts:241
Registered: 11/2/03
Re: Can't Find MySQL driver in JSP   
Jan 21, 2006 11:49 PM (reply 19 of 26)  (In reply to #18 )

 
I found that my problem was cause by omitting ${ in query.

<sql:query dataSource="${name-in-var}"
 
Raj_Delhi
Posts:20
Registered: 12/15/05
Re: Can't Find MySQL driver in JSP   
Jan 22, 2006 12:21 AM (reply 20 of 26)  (In reply to #19 )

 
well !! I have gone through ur problem today... I have resently used MySQL and was facing same kind of problem but with me It was solved by putting:

mysql-connector-java-3.1.12-bin.jar file
into
<Java:Home>\jre\lib\ext folder.

If you are still facing connection problem try it.
 
omar_slomic
Posts:1
Registered: 1/29/06
Re: Can't Find MySQL driver in JSP   
Jan 29, 2006 9:07 AM (reply 21 of 26)  (In reply to #20 )

 
I had the same problem but i changed uri in taglib directive from http://java.sun.com/jstl/sql to http://java.sun.com/jsp/jstl/sql and everything worked fine for me.

You got to have dataSource attribute in sql:query-tag with ${} or else you will get "no driver...." -error message
 
Fava
Posts:2
Registered: 2/24/06
Re: Can't Find MySQL driver in JSP   
Feb 24, 2006 9:02 PM (reply 22 of 26)  (In reply to original post )

 
I meet the same proble. More strange...

<sql:setDataSource var="myconn" url="jdbc:mysql://localhost/mysql" user="root" driver="com.mysql.jdbc.Driver" />
<c:out value="${myconn}" />

it worked!
but when i added script below

<sql:query var='myhost' dataSource="${myconn}">
select host from user
</sql:query>
it give the message :
Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
 
Fava
Posts:2
Registered: 2/24/06
Re: Can't Find MySQL driver in JSP   
Feb 25, 2006 4:53 AM (reply 23 of 26)  (In reply to original post )

 
Hi, I have sovled the problem! I am very happy, course the problem trouble me for a long time!
I use NetBeans5.5 and the server bundled is Sun Java System Application Server.
I copy the mysql -connector-*.jar to AppServer\lib and restart it!
I just a beginer.
Thanks!
 
JOlegOOP
Posts:8
Registered: 11/25/04
Re: Can't Find MySQL driver in JSP   
Mar 24, 2006 6:47 AM (reply 24 of 26)  (In reply to #15 )

 
Thanks, guys! You're life savious for those who search for similar problems via search. Found the solution here. In my case it was the matter of missing $ sign
 
Theepan
Posts:17
Registered: 7/13/06
Re: Can't Find MySQL driver in JSP   
Aug 14, 2006 12:56 PM (reply 25 of 26)  (In reply to #24 )

 
This one helped me Solve the problem>>>>>
http://www.java2s.com/Code/Java/JSTL/SQLTagOutExamples.htm
http://www.java2s.com/Code/JavaDownload/JSTL-Data-Table-Access.zip
 
appy77
Posts:1,001
Registered: 02/04/99
Re: Can't Find MySQL driver in JSP   
Mar 10, 2007 7:12 PM (reply 26 of 26)  (In reply to #25 )

 
I solved this problem to.

If you are using MySQL 5.x database then the solution is to have the following in your Web application's lib folder - basically the JAR files can be located anywhere as long as they are visible to the tool (IDE, command line etc) that you use to run your program.

The required JAR files for MySQL 5.x are:
mysql-connector-java-5.0.5-bin.jar
aspectjrt.jar

Test with the following code it should work:
package jdbcTest;
 
import java.sql.*;
 
public class TestJdbcConnection {
    public static void main(String[] args) {
        TestJdbcConnection tjc = new TestJdbcConnection();
        try {
            tjc.testConnection();
        } catch (SQLException e) {
            e.printStackTrace(); 
        } catch (ClassNotFoundException cnfe) {
            cnfe.printStackTrace();
        }
 
 
    }
 
    private void testConnection() throws SQLException, ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
        //jdbc:mysql://host_name:port/dbname
        /*
        This requires MySQL Connector JAR file: mysql-connector-java-5.0.5-bin.jar and
         aspectjrt.jar - Make sure that both JAR files are visible in the classpath
         used by whatever tool (IDE, Command line etc) is used to run this main.
        */
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/schema_name", "username", "secret");
 
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT 'xyz' as a FROM dual");
        while (rs.next()) {
            String s = rs.getString("a");
            System.out.println(" s is : " + s);
        }
    }
}
 
 
This topic has 26 replies on 2 pages.    « Previous | 1 | 2 |
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 28
  • Guests : 133

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums