- I've created a Java class for the controller, called "pageController.java"
- Another java class that includes the date getter and setter, "pages.java"
- A JSP to display the date coding:
<label class="label" name="date" ></label>
The name "date" will pass to the getter and setter in pages.java:
private String date;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public pages (){}
Lastly, the page Controller has (import pages.java)
public class pageController {
static Statement stmt = null;
static Connection conn = null;
public static void main(String[] args) throws SQLException{
String connectionURL = "jdbc:mysql://localhost:8888/diario";
pages p = new pages();
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(connectionURL, "root", "narumi");
stmt = conn.createStatement();
String sql;
sql = "Select CURDATE() AS today";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()){
p.setDate(rs.getString(1));
}
rs.close();
stmt.close();
conn.close();
}catch (SQLException e){
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
After running the JSP, nothing shows. IDE I'm using is intelliJ IDEA 15