Search code examples
mysqljspjdbcjstl

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found"


I write simple code in jsp and want to get a query from data base and show it in this page . my data base is created and have some sample data in , but when i write :

        <sql:setDataSource  var="co"   driver="com.mysql.jdbc.Driver" 
                        url="jdbc:mysql://localhost:3306/sys3"

                        user="root"
                        password="amir"
                        />
    <sql:query var="res" dataSource="co">
        Select sec_id from section
    </sql:query>

it show this error on glassfish server :

javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found"


Solution

  • Download mysql-connector.jar from here and add it to your classpath One more thing change

    <sql:query var="res" dataSource="co">
    

    to

    <sql:query var="res" dataSource="${co}">