I am trying to connect my database in a java file and then use that java file inside a jsp file to show the contents of the database but i keep getting multiple annotations error.
Java File
package library;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Book {
public ResultSet database()throws Exception
{
final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
final String DB_URL = "jdbc:mysql://localhost/Library";
final String USER = "root";
final String PASS = "asdfghjkl";
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
try
{
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL,USER,PASS);
stmt = conn.createStatement();
String query = "SELECT * FROM books";
rs = stmt.executeQuery(query);
}
catch(Exception e)
{
}
rs.close();
stmt.close();
conn.close();
return rs;
}
}
Jsp File
<%@page import="library.Book" %>
<%@page import="java.sql.ResultSet" %>
<html>
<head>
</head>
<%
ResultSet rs = database();
%>
<body>
</body>
</html>
The error is :
Multiple annotations found at this line: - The method database() is undefined for the type __2F_Library_20_Management_2F_WebContent_2F_Books_2E_jsp - The method database() is undefined for the type __2F_Library_20_Management_2F_WebContent_2F_Books_2E_jsp