class 的方法在远程 Web 服务器中不起作用,但在本地起作用

a method of class is not working in remote web server but working locally

我开发了一个 jsp(网络应用程序),其中有一个 class 包 vdb,其中包含 class Db,其源代码在下方,jsp 文件正在使用方法 connect() 其中 return Connection 对象和 year() 其中 return 一个整数值。

方法 connect() 在两种情况下(在远程服务器或本地主机中)都运行良好,但方法 year() 在本地主机的情况下运行良好,但在远程服务器(openshift)中不起作用。

文件Db.java

package vdb;

import java.sql.*;

public class Db {
public static synchronized  Connection connect()
{
    Connection con=null;
    try{
    String url    =  "jdbc:mysql://1xx.x.xx.x:xx06/";
        String db     =  "mydb";
        String driver =  "com.mysql.jdbc.Driver";
        String user   = "adminaz";
        String pass   = "mypassword";
          Class.forName(driver).newInstance();
          con = DriverManager.getConnection(url+db,user,pass);

    }
    catch(Exception e)
    {
    }
    return con;
}

public static int year()
{
int y=0;
ResultSet rs=null;
try
{
    Connection con=connect();
Statement st=con.createStatement();
rs=st.executeQuery("SELECT MAX(START) FROM SESSION");
    rs.next();
y=rs.getInt(1);
}
catch (Exception e) 
{
    System.out.println(e);
}
    return y;
}
}

文件index.jsp

<%@page import="java.sql.*;"pageEncoding="UTF-8"%>
<% int y= vdb.Db.year();%>
 <%out.println(" CURRENT YEAR "+y);%>

这个有什么问题还是error.How要克服。

代码没有问题。 问题出在使用 table 名称的情况下。 本地主机在 WINDOW OS 上,而远程 Web 服务器 (OPENSHIFT) 基于 Linux 并且默认在 Linux OS mysql table 名称区分大小写, 大小写不匹配导致的异常

在 linux 中,默认情况下 mysql 查询区分大小写,但在 window 中则不区分大小写。