title: Display data from database using java
body: <p>I'm trying to make a connection with MySQL datatbase and I'm using Tomcat v6.0. The source code in Java is this:</p>
  
  <p>ConnectionManager.java</p>
  
  <pre><code>package admin;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  
  
  public class ConnectionManager {
      private static ConnectionManager instance = null;
  
      private static final String USERNAME = "root";
      private static final String PASSWORD = "";
      private static final String CONN_STRING =
              "jdbc:mysql://localhost/sondazh";
  
      private Connection conn = null;
  
      private ConnectionManager() {
      }
  
      public static ConnectionManager getInstance() {
          if (instance == null) {
              instance = new ConnectionManager();
          }
          return instance;
      }
  
      private boolean openConnection() throws ClassNotFoundException {
          try {
  
              conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
              return true;
          } catch (SQLException e) {
              e.printStackTrace();
          }
  
          return false;
  
      }
  
      public Connection getConnection() {
          if (conn == null) {
              try {
                  if (openConnection()) {
                      return conn;
                  } else {
                      return null;
                  }
              } catch (ClassNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
          return conn;
      }
  
      public void close() {
          try {
              conn.close();
              conn = null;
          } catch (Exception e) {
          }
      }
  
  }
  </code></pre>
  
  <p>DatabaseObject.java</p>
  
  <pre><code>package admin;
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.Statement;
  
  import javax.swing.JOptionPane;
  
  public abstract class DatabaseObject {
  
      private static Connection conn = ConnectionManager.getInstance()
              .getConnection();
  
      public static ResultSet query(String sql) {
          try {
              PreparedStatement stmt = conn.prepareStatement(sql);
              ResultSet rs = stmt.executeQuery();
              return rs;
          } catch (Exception e) {
              JOptionPane.showMessageDialog(null, e.getMessage());    
              System.out.println(e.getMessage());
              return null;
          }
      }
  
      public static boolean update(String sql){
          try {
              PreparedStatement stmt = conn.prepareStatement(sql);
              int affected = stmt.executeUpdate();
  
              if(affected == 0){
                  return false;
              }
  
              return true;
          } catch (Exception e) {
              System.out.println(e.getMessage());
              return false;
          }
      }
  
      public static int insert(String sql){
          try {
              Statement stmt = conn.createStatement();
              int affected = stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS);
  
              return affected;
          } catch (Exception e) {
              return 0;
          }
      }
  }
  </code></pre>
  
  <p>I also have created getter and setter for all entities in my database 
  but when I run it shows me an error:</p>
  
  <p>HTTP Status 404 - type Status report</p>
  
  <p>message</p>
  
  <p>description The requested resource is not available.</p>
  
  <p>Apache Tomcat/6.0.36</p>
  
  <p>i want to display some data from User entity :</p>
  
  <pre><code>test.jsp
  
  &lt;%@page import="java.sql.Connection"%&gt;
  &lt;%@page import="java.sql.ResultSet"%&gt;
  &lt;%@page import="admin.User"%&gt;
  &lt;%@page import="admin.ConnectionManager"%&gt;
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt; test &lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div&gt;
          &lt;table&gt;
              &lt;%
              ResultSet rs = User.loadAll(); 
                  while (rs.next()) { 
              %&gt; 
  
              &lt;tr&gt;
                 &lt;TH&gt;ID&lt;/TH&gt;
                 &lt;TH&gt;Name&lt;/TH&gt;
                 &lt;TH&gt;Surname&lt;/TH&gt;
                 &lt;TH&gt;Email&lt;/TH&gt;
  
             &lt;/tr&gt;
             &lt;tr&gt;
                 &lt;td&gt; &lt;%= rs.getInt(1) %&gt; &lt;/td&gt;
                 &lt;td&gt; &lt;%= rs.getString(2) %&gt; &lt;/td&gt;
                 &lt;td&gt; &lt;%= rs.getString(3) %&gt; &lt;/td&gt;
                 &lt;td&gt; &lt;%= rs.getString(4) %&gt; &lt;/td&gt;
  
  
             &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  
         &lt;% 
             } 
         %&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is test.jsp that i try to run but i can't get the result that i want because of error that i mentioned earlier . Tomcat is running. Is my jsp code ok?</p>