簡體   English   中英

無法在Jelastic中連接到mysql數據庫

[英]Not able to connect to mysql database in jelastic

我無法連接到從系統導入的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;
}

您需要獲取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());
}

更多代碼示例:

當您遇到確切的錯誤時,應該很容易解決問題。 沒有它,不幸的是一切都只是猜測!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM