我想在网页上随机显示图像及其信息。每隔一段时间它应该会自动更改图像并在浏览器中查看。我如何使用 java 和 oracle 数据库做到这一点我只是尝试创建一个计时器,然后尝试调用以下查询,但它不起作用
SELECT *
FROM (
SELECT name
FROM employee
ORDER BY
dbms_random.value
)
WHERE rownum <= 1000
& 然后在计时器运行方法中,我像这样调用这个查询。
TimerTask task = new TimerTask(){
public void run()
{
//execute the code for every 10 mins
Timer timer = new Timer();
timer.scheduleAtFixedRate(task, 0, 10 * 60 * 1000); // period is 10 mins
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:
@localhost:1521:orcl","Admin","secret");
Statement st=con.createStatement();
System.out.println("connection established successfully...!!");
ResultSet rs=st.executeQuery("SELECT *\n" +
"FROM (\n" +
" SELECT name\n" +
" FROM employee\n" +
" ORDER BY\n" +
" dbms_random.value\n" +
" )\n" +
"WHERE rownum <= 1000");
// pw.println("<table border=1>");
while(rs.next())
{
System.out.println("<br>"+"Id :"+rs.getInt("name"));
}
// pw.println("</table>");
}
catch (Exception e){
e.printStackTrace();
}
}
};