mysql - 连接到 OpenShift 的 mysql 时表不存在

标签 mysql tomcat openshift

我将 Java 应用程序上传到 OpenShift 应用程序。 它具有以下墨盒:

  • Tomcat 7 (JBoss EWS 2.0)
  • MySQL 5.5
  • phpMyAdmin 4.0

Rhc、git 和 ssh 都正常工作。但是当我运行我的应用程序时,它无法访问我数据库中的表。当我把所有东西都放在我的电脑上时,一切正常,当我尝试部署到 OpenShift 时出现了这个问题。

我得到以下异常:

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'mytomcatapp.ordenesDeCompra' doesn't exist

这就是我在我的应用程序中连接到数据库的方式:

private static final String host = System.getenv("OPENSHIFT_MYSQL_DB_HOST");
private static final String port = System.getenv("OPENSHIFT_MYSQL_DB_PORT");
private static final String stringConexion = String.format("jdbc:mysql://%s:%s/mytomcatapp", host, port);

private static Connection conexion;

public static void conectar() {

    try {
        Class.forName("com.mysql.jdbc.Driver");
        conexion = DriverManager.getConnection(stringConexion, "myUser", "myPassword");

    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(ConexionBD.class.getName()).log(Level.SEVERE, null, ex);
    }
}

然后在 Controller 中,我使用之前创建的连接执行一个简单的查询。

当我使用 ssh 连接到 mysql 时,我可以看到我的数据库和表存在:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| mytomcatapp        |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

mysql> use mytomcatapp; go; show tables;
Database changed
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'go' at line 1
+-----------------------+
| Tables_in_mytomcatapp |
+-----------------------+
| jurisdicciones        |
| ordenesdecompra       |
| proveedores           |
| subtitulos            |
| tiposcontratacion     |
+-----------------------+
5 rows in set (0.00 sec)

最佳答案

您的表名有误,请注意,在 Unix 上,SQL 中的表名区分大小写,即使在 Windows 上它们可能不区分大小写(检查:Are table names in MySQL case sensitive? 以获得解释)

因此,您应该访问 ordenesdecompra 而不是访问 ordenesDeCompra

关于mysql - 连接到 OpenShift 的 mysql 时表不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35981682/

相关文章:

tomcat - 不允许使用 Squareup iFrame

java - 无法通过 Openshift 中的 mysql 数据库登录

curl - OpenShift 3.1 - 防止 Docker 缓存 curl 资源

mysql - select mysql 查询的性能真的很差

javascript - mysql中使用单引号时出错

git - Maven Git 存储库

java - 在tomcat服务器中加载Jar

kubernetes - 有没有办法通过 Kubernetes API 服务器代理转发授权头?

c# - 在表适配器配置向导 Visual Studio 2015 中更改超时

mysql约束无法添加