修改从Oracle里面读取出来的时间格式


		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
			conn = DriverManager.getConnection(
					"jdbc:oracle:thin:@localhost:1521:orcl", "zhang",
					"zhang");
			stmt = conn.createStatement();
			String url = "select * from (select * from you order by time desc) where rownum<=5";
			rs = stmt.executeQuery(url);
			while (rs.next()) {
				//out.print(rs.getString("name"));
				SimpleDateFormat sd=new SimpleDateFormat("yyyy:MM:dd hh:mm:ss");
				String showtime=sd.format(rs.getTimestamp("time"));
				out.print(showtime);
				out.print("<br/>");
				out.print(rs.getString("discuss"));
				out.print("<br/>");
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (stmt != null) {
					stmt.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}





Connection con = null;
		Statement stm = null;
		ResultSet res = null;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
			con = DriverManager.getConnection(
					"jdbc:oracle:thin:@localhost:1521:orcl", "zhang",
					"zhang");
			stm = con.createStatement();
			rs = stm.executeQuery("select * from (select t.*,to_char(t.time,'yyyy-mm-dd hh:mm:ss') time1 from recommend t order by t.time desc)where rownum<=3 ");
			while (rs.next()) {
				out.print(rs.getString("introduce"));
				out.print(" ");
				out.print(rs.getString("time1"));
				out.print("<br/>");

你可能感兴趣的:(oracle,jdbc)