Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » no suitable driver found in jsp but not as java application
no suitable driver found in jsp but not as java application [message #1851223] Thu, 31 March 2022 08:02 Go to next message
Mehmet Kırlak is currently offline Mehmet KırlakFriend
Messages: 1
Registered: March 2022
Junior Member
I am using JSP for the first time and trying to do a web application.The problem I'm facing is that the Database connection works great if run from the App.java class, but if I run it from the JSP file it will throw a SQLException saying it didn't find a suitable driver. I put the driver in the server's classpath, in the WEB-INF/lib, in the project's build path as external JAR.

environment:
Microsoft SQL Server 2017,
sqljdbc_10.2/mssql-jdbc-10.2.0.jre11.jar
server:Tomcat v10.0.13
eclipse java ee ide

Error message:

Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name: Apache Tomcat/10.0.13
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Nov 9 2021 22:12:58 UTC
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 10.0.13.0
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 10
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.0
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Users\kirla\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.0.v20211012-1059\jre
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 17+35
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Eclipse Adoptium
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\kirla\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Users\kirla\Downloads\apache-tomcat-10.0.13
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\kirla\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Users\kirla\Downloads\apache-tomcat-10.0.13
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\kirla\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1254
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -XX:+ShowCodeDetailsInExceptionMessages
Mar 31, 2022 10:43:57 ÖÖ org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [C:\Users\kirla\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.0.v20211012-1059\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Users/kirla/eclipse//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.2.v20220201-1208/jre/bin/server;C:/Users/kirla/eclipse//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.2.v20220201-1208/jre/bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\dotnet\;C:\Users\kirla\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Azure Data Studio\bin;C:\Users\kirla\AppData\Local\GitHubDesktop\bin;C:\Users\kirla\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files (x86)\Brackets\;C:\Users\kirla\.dotnet\tools;C:\Users\kirla\eclipse;;.]
Mar 31, 2022 10:43:58 ÖÖ org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Mar 31, 2022 10:43:58 ÖÖ org.apache.catalina.startup.Catalina load
INFO: Server initialization in [1261] milliseconds
Mar 31, 2022 10:43:58 ÖÖ org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Mar 31, 2022 10:43:58 ÖÖ org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/10.0.13]
Mar 31, 2022 10:43:59 ÖÖ org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 31, 2022 10:43:59 ÖÖ org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Mar 31, 2022 10:43:59 ÖÖ org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Mar 31, 2022 10:43:59 ÖÖ org.apache.catalina.startup.Catalina start
INFO: Server startup in [1139] milliseconds
oopss
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://DESKTOP-EFD0KAH:1433;DatabaseName=Blog;encrypt=true;trustServerCertificate=true
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:706)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:229)
at Controller.DBConnection.connDb(DBConnection.java:23)
at Controller.BlogController.<init>(BlogController.java:14)
at org.apache.jsp.View.cevap_jsp._jspService(cevap_jsp.java:133)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:872)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1695)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
Mar 31, 2022 10:44:00 ÖÖ org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/WebApplication] threw exception [An exception occurred processing [View/cevap.jsp] at line [50]

47: <div class="col-10">
48: <%
49:
50: List<BlogModel> list=ozelBlog.getBlogList();
51:
52: for(BlogModel blog:list){
53:


Stacktrace:] with root cause
java.lang.NullPointerException: Cannot invoke "java.sql.Connection.createStatement()" because "this.conn" is null
at Controller.BlogController.getBlogList(BlogController.java:23)
at org.apache.jsp.View.cevap_jsp._jspService(cevap_jsp.java:176)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328)
at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:872)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1695)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)

Here is my Java codes.

DBConnection.java

package Controller;

import java.sql.*;

public class DBConnection {
	
	public Connection con = null;
	public String host = "localhost";
	public String serverName = "DESKTOP-EFD0KAH";
	public int port = 1433;
	public String dbName = "Blog";
	public String properties = "encrypt=true;trustServerCertificate=true";
	//public String url = "jdbc:sqlserver://DESKTOP-EFD0KAH:1433;DatabaseName= Hospital ;encrypt=true;trustServerCertificate=true";
	public String url = "jdbc:sqlserver://"+serverName+":"+port+";DatabaseName="+dbName+";"+properties;
	public String user="sa";
	public String password="123";
	
	
	public DBConnection() {}
	
	public Connection connDb() {
		try {
			this.con = DriverManager.getConnection(url,user,password);
			System.out.println("connected.");
			return con;
		} catch (SQLException e) {
			System.out.println("oopss");
			e.printStackTrace();
		}
		return con;
	}

}



BlogController.java

package Controller;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.ArrayList;

import Model.BlogModel;

public class BlogController extends DBConnection {
	DBConnection con = new DBConnection();
	Connection conn = con.connDb();
	Statement st = null;
	ResultSet rs = null;
	
	public ArrayList<BlogModel> getBlogList() throws SQLException {
		ArrayList<BlogModel> list = new ArrayList<>();
		BlogModel post;
		try {
			String sorgu = "SELECT * FROM post";
			st = conn.createStatement();
			rs = st.executeQuery(sorgu);
			while (rs.next()) {
				post = new BlogModel(rs.getInt("id"), rs.getString("title"), rs.getString("body"),
						rs.getString("createdAt"), rs.getInt("published"));
				list.add(post);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}
}



and the index.jsp

<%@page import="org.apache.coyote.ContinueResponseTiming"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<%@page import="Controller.BlogController,Model.BlogModel,java.util.*,java.sql.*"%>


<%
	BlogController ozelBlog = new BlogController();
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link
	href="htstss"
	rel="stylesheet"
	integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
	crossorigin="anonymous">
<link rel="stylesheet"
	href="hare.()/ajamin.css"
	integrity="sha512-9usAa10IRO0HhoUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg=="
	crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="preconnect" href="hts.( those are link)">
<link rel="preconnect" href="htatic." crossorigin>
<link
	href="htss2?fa=swap"
	rel="stylesheet">
<link rel="stylesheet" href="style.css">
<title>Awesome Blog</title>
</head>
<body>
	<main>
		<div class="bg-dark px-4 py-5 text-center text-white">
			<div class="container my-4">
				<div class="latest">
					<p>Latest posts...</p>
				</div>
				<div class="card-group text-dark">
					<div class=" row"
						style="width: 100%; background-image: url(../img/thumb-1920-190787.jpg)">


						<div class="col-2"></div>
						<div class="col-10">
							<%
							
							List<BlogModel> list=ozelBlog.getBlogList();
							
							for(BlogModel blog:list){
								
								
							%>
							<div class="card m-5">
								<img class="card-img-top" src="img/1.jpeg" alt="Card image cap">
								<div class="card-body">
									<h5 class="card-title">
										<%
										blog.getTitle();
										%>
									</h5>
									<p class="card-text">
										<%
										blog.getBody();
										%>
									</p>
								</div>
								<div class="card-footer">
									<small class="text-muted">
										<%
										blog.getCreatedAt();
										%>
									</small>
								</div>
							</div>
							<%
							}
							%>

						</div>
					</div>


				</div>
			</div>
		</div>
	</main>
</body>
</html>


index.php/fa/41837/0/

Thanks.
Re: no suitable driver found in jsp but not as java application [message #1851238 is a reply to message #1851223] Thu, 31 March 2022 14:13 Go to previous message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4267
Registered: July 2009
Senior Member

"I put the driver in the server's classpath, in the WEB-INF/lib, in the project's build path as external JAR."

Which one is it? And are you sure it doesn't require any native DLLs?


Nitin Dahyabhai
Eclipse Web Tools Platform

[Updated on: Thu, 31 March 2022 17:10]

Report message to a moderator

Previous Topic:Developer Issue with eclipse Neon IDE delivering log4j 1.2.15 version which is vulnerability
Next Topic:Toggle line comment in Javascript file
Goto Forum:
  


Current Time: Thu Oct 06 05:14:26 GMT 2022

Powered by FUDForum. Page generated in 0.04614 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top