title: Java DB connection
body: <p>I have a java project with many files that connects to the database. Can anyone tell me if it is possible to use a java class file for connecting to the database so that I won't create a  Database connection for every file and please teach me how.. thanks for the help :D
  Here's the code I used but it didn't work</p>
  
  <p>dbConnect.java - class file</p>
  
  <pre><code>    public class dbConnect {
  
          public static void connect(){
          Connection conn;
          Statement stmt;
          ResultSet rs;
  
          String sql;
              conn = null;
              String url = "jdbc:mysql://localhost:3306/db_oopproject";
              String driver = "com.mysql.jdbc.Driver";
              try{
                  Class.forName(driver).newInstance();
                  conn = DriverManager.getConnection(url,"user","12345");
  
                  stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                  sql = "Select * from user_account";
                  rs = stmt.executeQuery(sql);
  
              }
              catch (Exception e){
                  System.out.print(e.getMessage());
              }
          }
  
  
      }
  </code></pre>
  
  <p>I called this class in the main file using this dbConnect.connect();
  Is there anything wrong with the code?</p>