0

how to connect mysql database from server on netbeans

try {
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/pmsdb", "root", "");
    return con;
} catch(Exception e) {
    System.out.println(e);
    return null;
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
kingnigus
  • 1
  • 1
  • 1
    Hello and welcome. Is this giving you any error? Did you include the appropriate jdbc driver in your classpath? Please give us a bit more to work with. – Federico klez Culloca Nov 12 '21 at 13:31

1 Answers1

-1

There is a standard idiom to create a JDBC connection ... You can debug you configuration by just using this class and clicking the "Run" button in your IDE.

If it does not work for you add the error output to the original question and we can debug further.

public class JdbcConnection {
 
    public static void main(String a[]){
         
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.
                getConnection("jdbc:oracle:thin:@<hostname>:<port num>:<DB name>"
                    ,"user","password");
            Statement stmt = con.createStatement();
            System.out.println("Created DB Connection....");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Arthur Klezovich
  • 2,595
  • 1
  • 13
  • 17