title: Java newbie needs help in database connection
body: <p>I'm new to Java and even newer to java database connections. I've managed to create a database connection and query a table when I put it in the Main class. Now that I've moved it into a new class called Connection I am getting errors:</p>
  
  <pre><code>package lokate;
  
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.sql.ResultSet;
  
  public class Connection {
  
  private static Statement stmt = null;
  private static ResultSet rs = null;
  private static Connection con = null;
  
  public Connection() throws SQLException {
      try {
          Class.forName("com.mysql.jdbc.Driver");
          String connectionUrl = "jdbc:mysql://localhost:3306/Lokate?" +
                                 "user=root&amp;password=";
          con = DriverManager.getConnection(connectionUrl);
          stmt = con.createStatement();
          retriveData("SELECT * FROM Users");
          int rowsEffected = 0;
      } catch (SQLException sqlEx) {
          System.out.println("SQL Exception: "+ sqlEx.toString());
      } catch (ClassNotFoundException classEx) {
          System.out.println("Class Not Found Exception: "+ classEx.toString());
      } catch (Exception Ex) {
          System.out.println("Exception: "+ Ex.toString());
      }
  }
  
  public static void retriveData(String SQL) throws Exception {
      rs = stmt.executeQuery(SQL);
      while (rs.next()) 
      {
          System.out.println(rs.getString("fname") + " : " + rs.getString("lname"));
      }
  }
  
  }
  </code></pre>
  
  <p>I'm getting an error saying cannot find symbol. Symbol:method createStatement() and incomparable types for con = DriveManager.....</p>
  
  <p>Can anyone help?</p>
  
  <p>Also, is it best practice to put the connection in the class like this then call a new object every time I want to do something with the db?</p>
  
  <p>Regards,</p>
  
  <p>Billy</p>