Jdbc连接Postgresql数据库

附件为所需jar文件。

package com.dao.base;

import java.sql.*;
import java.util.Properties;

public class TestJdbc {
	
	/** Oracle数据库连接URL */
	private final static String Oracle_URL = "jdbc:postgresql://127.0.0.1:5432/postgres";
	/** Oracle数据库连接驱动 */
	private final static String Oracle_DRIVER = "org.postgresql.Driver";
	/** 数据库用户名 */
	private final static String Oracle_USERNAME = "postgres";
	/** 数据库密码 */
	private final static String Oracle_PASSWORD = "postgres";

	public static void main(String[] args) throws SQLException {
		try {
			Class.forName(Oracle_DRIVER);
			Connection conn = DriverManager.getConnection(Oracle_URL,
					Oracle_USERNAME, Oracle_PASSWORD);
			Statement stmt = conn.createStatement();
			stmt.executeQuery("select to_char(now(),'yyyy-MM-DD') as a");

			System.out.println("success!");
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("failer!");
		}
	}

}

你可能感兴趣的:(PostgreSQL)