简体   繁体   中英

Not able to connect to mysql database in jelastic

i am not able to connect to mysql database which i imported from my system.i have added user to my imported database and giving the same user name and password in code yet there is no connection from my war app to database.my war app is retrieving nothing from imported multiclouddata database my code as follows.... (i am a trial user)

package DBClass;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class DataBaseClass 
{
Connection con=null;
Statement st=null;
ResultSet rs=null;
String host="jdbc:mysql://mysql-userapp.jelastic.servint.net/MultiCloudData";
    String username="test1";
    String password="LQ53fvGRYryyaveW";
    String driver="com.mysql.jdbc.Driver";
PreparedStatement pst;
public Connection getConnection()
{
    try
    {

        Class.forName(driver);

            con = DriverManager.getConnection(host ,username,password);
        System.out.println("Connection is ok......");
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    return con;
}

You need to get the SQLException to find out the root cause of the problem.


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

Connection conn = null;
...
try {
    conn =
       DriverManager.getConnection("jdbc:mysql://localhost/test?" +
                                   "user=monty&password=greatsqldb");

    // Do something with the Connection

   ...
} catch (SQLException ex) {
    // handle any errors
    System.out.println("SQLException: " + ex.getMessage());
    System.out.println("SQLState: " + ex.getSQLState());
    System.out.println("VendorError: " + ex.getErrorCode());
}

More code examples:

When you have the exact error, it should be easy to fix the problem. Without it everything is just guesswork unfortunately!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM