连接到云SQL时收到套接字错误

时间:2017-07-30 11:30:08

标签: android sockets google-app-engine google-cloud-sql

我正在尝试使用android studio连接到云端SQL。收到此错误

public void getDatafromSQL() {
    Log.d("GeoL", "getSQL");
    Connection connection;
    String query = "Some query";
    try {
        String databaseName = "dbName";

        String instanceConnectionName = "instnce name";

        String jdbcUrl = String.format(
                "jdbc:mysql://google/%s?cloudSqlInstance=%s&"
                        + "socketFactory=com.google.cloud.sql.mysql.SocketFactory",
                databaseName,
                instanceConnectionName);
        connection = DriverManager.getConnection(jdbcUrl, "user", "pwd");

        Statement statement = connection.createStatement();
        ResultSet resultSet = statement.executeQuery(query);
        Log.d("GeoL", String.valueOf(resultSet));
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

我的代码:

Traceback (most recent call last):

  File "./odoo-bin", line 5, in <module>
    __import__('pkg_resources').declare_namespace('odoo.addons')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2218, in declare_namespace
    declare_namespace(parent)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2234, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2201, in _handle_ns
    loader.load_module(packageName)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pkgutil.py", line 246, in load_module
    mod = imp.load_module(fullname, self.file, self.filename, self.etc)
  File "/Users/Mohamed_mac/odoo/odoo/__init__.py", line 60, in <module>
    import modules
  File "/Users/Mohamed_mac/odoo/odoo/modules/__init__.py", line 8, in <module>
    from . import db, graph, loading, migration, module, registry
  File "/Users/Mohamed_mac/odoo/odoo/modules/graph.py", line 13, in <module>
    import odoo.osv as osv
  File "/Users/Mohamed_mac/odoo/odoo/osv/__init__.py", line 4, in <module>
    import osv
  File "/Users/Mohamed_mac/odoo/odoo/osv/osv.py", line 4, in <module>
    from ..exceptions import except_orm
  File "/Users/Mohamed_mac/odoo/odoo/exceptions.py", line 15, in <module>
    from tools.func import frame_codeinfo
  File "/Users/Mohamed_mac/odoo/odoo/tools/__init__.py", line 8, in <module>
    from misc import *
  File "/Users/Mohamed_mac/odoo/odoo/tools/misc.py", line 16, in <module>
    import passlib.utils
ImportError: No module named passlib.utils
 i hope u to help me, thank you

我使用mysql连接器jar和mysql socket工厂jar作为依赖项。

此外,我无法使用编译com.google.cloud.sql:mysql-socket-factory:1.0.3&#39;这是一种依赖。

请帮忙。

提前致谢。

1 个答案:

答案 0 :(得分:0)

该库包含多个罐子。如果你手动添加jar,你还需要添加它的依赖项(例如jdbc-socket-factory-core jar,也许是其他的)。

话虽如此,你真的不应该手动包装罐子,因为这是一个单调且容易出错的过程。

最后,除非这是您自己的玩具应用程序,否则您不应该通过移动应用程序直接连接到数据库。您实际上是向拥有该应用程序副本的任何人直接访问您的数据库。