0 votes
1 view
in Java by (9.5k points)

I want to connect a MS Access database mis.accdb with my java file ShowData.java. Below is the contents of ShowData.java:

import java.beans.Statement;

import java.io.IOException;

import java.io.PrintWriter;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class ShowData extends HttpServlet


public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException



PrintWriter out=response.getWriter();

Connection con=null;

Statement st=null;

ResultSet rs=null;






    } catch (SQLException ex) 


        Logger.getLogger(ShowData.class.getName()).log(Level.SEVERE, null, ex);


st=(Statement) con.createStatement();

rs=st.executeQuery("select * from student");

out.println("<table border='1'><tr><th>Student ID</th><th>Student Name</th><th>Branch</th></tr>");



int sid=rs.getInt("StudId");

String snm=rs.getString("StudName");

String br=rs.getString("Branch");







catch(ClassNotFoundException e)


out.println("Driver Loading Failed...");


catch(SQLException e)


out.println("Please Check SQL Query...");




When I implement this in IDE, it gives me the below error:

cannot find symbol

symbol: method executeQuery(String)

location: variable st of type Statement

Can anyone tell me why this happens and also help me to connect to the above specified MS Access Database mis.accdbin Netbeans? 

1 Answer

0 votes
by (19.7k points)

The import java.beans.Statement is wrong above. You also have to  remove the cast in below line:

st=(Statement) con.createStatement();

Interested in Java? Check out this Java tutorial by Intellipaat.  

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !