Q11.java 941 Bytes
Newer Older
Matias Ferreira committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
package com.roshka.jdbc;

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
			 * SELECT name 
			 * FROM courses
			 * WHERE EXTRACT('week' FROM start_date) 
			 * - EXTRACT('week' FROM CURRENT_DATE) = 1;
			 *  */ 
			
			Connection connection = DriverManager.getConnection(url, user,password);
			System.out.println("estoy conectado a la base de datos");
			Statement st = connection.createStatement();
			String query = "SELECT name "
							+ "FROM courses "
							+ "WHERE EXTRACT('week' FROM start_date) "
							+ "- EXTRACT('week' FROM CURRENT_DATE) = 1;";
			
			ResultSet rs = st.executeQuery(query);
			while(rs.next() ) {
				String name = rs.getString("name");
				System.out.println(name);
			}
		}catch(SQLException e) {
			e.printStackTrace();;
		}
	}
}