简体   繁体   English

无法在Jelastic中连接到mysql数据库

[英]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) 我无法连接到从系统导入的mysql数据库。我已将用户添加到导入的数据库中,并在代码中提供了相同的用户名和密码,但从我的war应用程序到database没有连接。从导入的multiclouddata数据库中检索不到我的代码,如下所示。...(我是试用用户)

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. 您需要获取SQLException以找出问题的根本原因。


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! 没有它,不幸的是一切都只是猜测!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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