Jump to content


Photo

Problem with database connection using JAVA

database connection conexiondebasededatos conexion basededatos .war java

  • Please log in to reply
2 replies to this topic

#1 garoskul

garoskul

    Newbie

  • Members
  • 2 posts

Posted 06 October 2019 - 05:58 PM

Hi there!

 

I have a java web project that used jsp and servlet. I´ve done correctly all the database and there is no problem with that. In the section of MySql Databases I´ve created a new user and I attached it to the database created.

 

The problem is that I don´t get the connection to the database. I genere a .war file to be deployed .

 

I attach part of the code that I use to connect java to the database.

 

public class Clase_Conexion{
    private Connection cn;
    private String user="garoskul_garos";   //The user I created
    private String password="mypassword";
    private String url="jdbc:mysql://64.62.211.131:3306/prueba";   //I used hnny.heliohost.org fist and it doesn´t work

  public Clase_Conexion(){
    cn=null;
    try{
         Class.forName("com.mysql.jdbc.Driver");
        cn=DriverManager.getConnection(url,user,password);
            if(cn!=null){
                System.out.println("Conexion establecida");
            }
    }catch ( SQLException e){
        System.out.println("error al conectar"+e);
    }   catch (ClassNotFoundException ex) {
                Logger.getLogger(Clase_Conexion.class.getName()).log(Level.SEVERE, null, ex);
            }
  }

  public Connection getConnection(){
    return cn;
  }

 

 

Please if u don´t mine to help me I´ll be very grateful.

 

 



#2 wolstech

wolstech

    Rank X Member

  • Root Admin
  • 10,878 posts
  • Gender:Male
  • Location:Pennsylvania

Posted 06 October 2019 - 06:50 PM

I assume this running on Johnny? If so, use localhost, not an IP or Johnny’s domain name.

If it’s running on your pc and connecting to Johnny for database services, be sure to enable remote MySQL connections in cPanel for your IP.

Please do not PM me for support. Posting on our forums lets all of us learn.
Do you play Minecraft? | Server Monitors | And the Dumbass of the Decade award goes to...


#3 garoskul

garoskul

    Newbie

  • Members
  • 2 posts

Posted 07 October 2019 - 02:57 AM

Yes, it´s running on Johnny. I´ve used localhost how u told me but it doesn´t connect still.

I attach my code that I currently use:

 

public class Clase_Conexion{
    private Connection cn;
    private String user="garoskul";
    private String password="*****";
    private String url="jdbc:mysql://localhost:3306/prueba";
 
  public Clase_Conexion(){
    cn=null;
    try{
         Class.forName("com.mysql.jdbc.Driver");
        cn=DriverManager.getConnection(url,user,password);
            if(cn!=null){
                System.out.println("Conexion establecida");
            }
    }catch ( SQLException e){
        System.out.println("error al conectar"+e);
    }   catch (ClassNotFoundException ex) {
                Logger.getLogger(Clase_Conexion.class.getName()).log(Level.SEVERE, null, ex);
            }
  }
 

It could be the username or the password?

How I said I used the username that I created and matched to the database, or what username do I have to use?

 

I´m sorry for this and thank u very very much for your help







Also tagged with one or more of these keywords: database, connection, conexiondebasededatos, conexion, basededatos, .war, java

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users