no suitable driver found in jsp but not as java application Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of no suitable driver found in jsp but not as java application without wasting too much if your time.

The question is published on by Tutorial Guruji team.

So I’m starting a web application and I want to use JSP pages (I’ve used them before) to access dynamically to the database and retrieve data from different tables.

I have by now a basic DatabaseHelper class, an App class that only tests the DB helper connection and a simple query, and a jsp file. The problem I’m facing is that the Database connection works great if run from the class, but if I run it from the JSP file it will throw a SQLException saying it didn’t find a suitable driver. (I’ll leave code and error message below)

I’ve tried different options I’ve read here in StackOverflow and other pages: I put the driver in the server’s classpath, in the WEB-INF/lib, in the project’s build path as external JAR (this one works for the Java app class mentioned before)…

And here is the environment:

  • Database: Microsoft SQL Server 2017

  • Driver: sqljdbc42.jar

  • Server: Glassfish 4.0

  • IDE: Eclipse Oxygen.3

So any hint on how can I solve this problem and use the Database helper from the jsp file will be happily welcome.


Error message:

[2018-03-28T12:39:48.883+0200] [glassfish 4.0] [SEVERE] [] [pl.mais.db.DBHelper] [tid: _ThreadID=21 _ThreadName=http-listener-1(3)] [timeMillis: 1522233588883] [levelValue: 1000] [[

java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost;databaseName=campus_db;user=******;password=*****
    at java.sql.DriverManager.getConnection(
    at java.sql.DriverManager.getConnection(
    at org.apache.jsp.index_jsp._jspService(
    at org.apache.jasper.runtime.HttpJspBase.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.jasper.servlet.JspServletWrapper.service(
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(
    at org.apache.jasper.servlet.JspServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.catalina.core.StandardWrapper.service(
    at org.apache.catalina.core.StandardWrapperValve.invoke(
    at org.apache.catalina.core.StandardContextValve.invoke(
    at org.apache.catalina.core.StandardPipeline.doInvoke(
    at org.apache.catalina.core.StandardPipeline.invoke(
    at com.sun.enterprise.web.WebPipeline.invoke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.doService(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at org.glassfish.grizzly.http.server.HttpHandler.runService(
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(
    at org.glassfish.grizzly.ProcessorExecutor.execute(
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$

package pl.mais.general;

import pl.mais.db.DBHelper;

public class App {
    public static void main (String[] args) {
        DBHelper db = new DBHelper();;

package pl.mais.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

 * @author sergi
public class DBHelper {
    // JDBC driver name and database URL

    private final String JDBC_DRIVER = "";  
    private final String DB_URL = "jdbc:sqlserver://localhost;databaseName=campus_db;";

    //  Database credentials
    private static final String DB_USER = "*****";
    private static final String DB_PASS = "*****";

    private Connection conn = null;
    private Statement stmt = null;

    public DBHelper() {
        try {
        } catch (Exception e) {

    public void open() {
        try {
            String connectionUrl = DB_URL + "user=" + DB_USER + ";password=" + DB_PASS;
            //System.out.println("Connecting to database...");
            conn = DriverManager.getConnection(connectionUrl);
            //System.out.println("Creating statement...");
            stmt = conn.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(DBHelper.class.getName()).log(Level.SEVERE, null, ex);

    public void close() {
        try {
        } catch (SQLException ex) {
            Logger.getLogger(DBHelper.class.getName()).log(Level.SEVERE, null, ex);

    public String[] testSelectFaculties() {
        try {  
            // Create and execute an SQL statement that returns some data.  
            String SQL = "SELECT * FROM faculties";  
            stmt = conn.createStatement();  
            ResultSet rs = stmt.executeQuery(SQL);  
            ArrayList<String> results = new ArrayList<String>();
            // Iterate through the data in the result set and display it.  
            while ( {  
               results.add(rs.getString(1) + " - " + rs.getString(2)); 
               System.out.println(rs.getString(1) + " - " + rs.getString(2));

            return (String[])results.toArray();

         catch (Exception e) {  

        return null;


<%@page import="pl.mais.db.DBHelper"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

    DBHelper db = new DBHelper();;
    String[] faculties = db.testSelectFaculties();
    for (int i = 0; i < faculties.length; i++) {



Making the JDBC Driver JAR Files Accessible:

To integrate the JDBC driver into a GlassFish Server domain, copy the JAR files into the domain-dir/lib directory, then restart the server. This makes classes accessible to all applications or modules deployed on servers that share the same configuration.

Source: Oracle documentation.

We are here to answer your question about no suitable driver found in jsp but not as java application - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji