我正在開發一個春季啓動web應用程序(我的第一個應用程序),並且它在我將它部署到嵌入式tomcat服務器時正常工作。但是,當我將它部署在獨立的Tomcat服務器中時, accesss的database.I正在使用WebService的休息將數據傳遞到前端和我的網址會像春季啓動運行但獨立的tomcat不工作
http://localhost:8080/day_demand?day=3
但在我的獨立服務器,當我訪問 http://localhost:8080/WebApp/day_demand?day=3
(Web應用程序是我的項目名稱)
與數據庫的連接由以下代碼構成:
private Connection connectToDatabaseOrDie()
{
Connection conn = null;
try
{
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://localhost:5432/data_base";
conn = DriverManager.getConnection(url,"user", "password");
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
System.exit(1);
}
catch (SQLException e)
{
e.printStackTrace();
System.exit(2);
}
return conn;
}
private void populateListOfTopics(Connection conn, List<State> listOfBlogs,Timestamp start_time,Timestamp end_time,int zone_id)
{
try
{
String sql= "SELECT * FROM public.table where time >= ? and time <= ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1,start_time);
pstmt.setTimestamp(2,end_time);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
State blog = new State();
blog.year = rs.getInt ("year");
blog.month=rs.getInt ("month");
blog.day = rs.getInt ("day");
blog.hour = rs.getInt ("hour");
listOfBlogs.add(blog);
}
rs.close();
pstmt.close();
conn.close();
}
catch (SQLException se) {
System.err.println("Threw a SQLException creating the list of state.");
System.err.println(se.getMessage());
} catch (Exception e) {
System.out.println("Err");
e.printStackTrace();
}
}
我無法訪問data.Any幫助表示讚賞。
你檢查日誌?它是否給出了任何特定的錯誤。 –