I am using eclipse luna and created a project on jsp but unable to call a class from "conect " package defined in src folder of my project
ConnectionProviderForSql.java
package connect;
import java.sql.*;
public class ConnectionProviderForSql {
public static Connection con=null;
public static Connection getCon(){
try{
String DRIVER="com.mysql.jdbc.Driver";
String CONNECTION_URL="jdbc:mysql://localhost:3306/abc";
String USERNAME="username";
String PASSWORD="password";
Class.forName(DRIVER);
con=DriverManager.getConnection(CONNECTION_URL,USERNAME,PASSWORD);
if(con!=null){
System.out.println("connected");}
else{
System.out.println("not connected");
}
}catch(Exception e){e.printStackTrace();}
return con;
}
}
my jsp file
reseller.jsp
<%@page import="connect.ConnectionProviderForSql"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Connection con1=null;
Statement stmt =null;
ResultSet rs = null;
PreparedStatement ps=null;
String result="bla";
con1 = ConnectionProviderForSql.getCon();
%>
my browser output
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [14] in the generated java file: [/root/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work/Catalina/localhost/Panel/org/apache/jsp/reseller_jsp.java]
Only a type can be imported. connect.ConnectionProviderForSql resolves to a package
An error occurred at line: 17 in the jsp file: /reseller.jsp
ConnectionProviderForSql cannot be resolved
14: PreparedStatement ps=null;
15: String result="bla";
16:
17: con1 = ConnectionProviderForSql.getCon();
18:
I had tried related question but it dint solve my problem Why it cannot resolve the class i have imported the package Please help trying this for hours. Thanks