Q11.java 939 Bytes
Newer Older
Matias Ferreira committed
1 2 3 4 5 6 7 8 9 10 11 12

import java.sql.*;


public class Q11 {

	public static void main( String [] args ) {
		String url = "jdbc:postgresql://localhost:5433/testdb";
		String user = "test";
		String password = "pqntslc";
		try {
			/* QUERY
13
			 * SELECT name
Matias Ferreira committed
14
			 * FROM courses
15
			 * WHERE EXTRACT('week' FROM start_date)
Matias Ferreira committed
16
			 * - EXTRACT('week' FROM CURRENT_DATE) = 1;
17 18
			 *  */

Matias Ferreira committed
19 20 21 22 23 24
			Connection connection = DriverManager.getConnection(url, user,password);
			Statement st = connection.createStatement();
			String query = "SELECT name "
							+ "FROM courses "
							+ "WHERE EXTRACT('week' FROM start_date) "
							+ "- EXTRACT('week' FROM CURRENT_DATE) = 1;";
25
			System.out.println("A continuacion se lista los cursos que empiezan la semana que viene");
Matias Ferreira committed
26 27 28 29 30 31 32 33 34 35
			ResultSet rs = st.executeQuery(query);
			while(rs.next() ) {
				String name = rs.getString("name");
				System.out.println(name);
			}
		}catch(SQLException e) {
			e.printStackTrace();;
		}
	}
}