#Hii trying to connect my servlet/jsp project with mysql connector.
1 messages · Page 1 of 1 (latest)
<@&987246527741304832> please have a look, thanks.
You should be using Maven/Gradle to manage your dependencies.
do I have to create a new project for adding build tool?
also,it is working fine when I ran the code outside eclipse?(compiled and ran)
not sure what's happening with eclipse when using with dynamic web project
jar file showing here as well
No, you can add it to an existing project. And it depends on how you manage your classpath.
update:
created a java file and it's working.
but getting error while calling the same method from jsp
this is the jsp
<%@page import="com.tech.blog.helpers.ConnectionProvider"%>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jsp page reloaded</title>
</head>
<body>
<h1>Hello world!</h1>
<%
Connection conn=ConnectionProvider.getConnection();
%>
<h1><%= conn %></h1>
</body>
</html>
```\
Detected code, here are some useful tools:
< % @page
import = "com.tech.blog.helpers.ConnectionProvider" % > < % @page language = "java"import = "java.sql.*"contentType = "text/html; charset=UTF-8"pageEncoding = "UTF-8" % > < !DOCTYPE html > <html> <head> < meta charset = "UTF-8" > <title> jsp page reloaded < / title > < / head > <body> <h1> Hello world! < / h1 > < % Connection conn = ConnectionProvider.getConnection();
% > <h1> < %= conn % > < / h1 > < / body > < / html >
but getting error while calling the same method from jsp You do need to share your error.
servlet
package com.tech.blog.helpers;
import java.sql.*;
public class ConnectionProvider {
public static void main(String[] args) {
Connection c=ConnectionProvider.getConnection();
System.out.println(c);
}
public static Connection getConnection() {
Connection conn = null;
try {
//System.out.println(Driver.class);
if(conn==null) {
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/techblog","root","admin");
}
}
catch(Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return conn;
}
}
when I run as "java application"
when I select run on server
What do you mean with: I created a Java file and it's working?
I wanted to test whether it is working as java application?
The error indicates the driver's not available. So is it being bundled properly.
Well yes, but what/how did you test it?
it is now working now.
https://stackoverflow.com/questions/1585811/classnotfoundexception-com-mysql-jdbc-driver
the above "ConnectionProvider.java",
I first ran it as "java application" option on eclipse => it ran fine(i guess that means library is added correctly)
then i ran it as "run on server"=> it throws exception which i shared above
just now i have followed the steps mentioned in stackoverflow and it now working fine when "run on server"
working with IDE is hard 😅