postgresql的java实例肯定可用

前端之家收集整理的这篇文章主要介绍了postgresql的java实例肯定可用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
package com.post;

import org.postgresql.*;
import java.sql.*;

public class TestDB {

	public TestDB() {
	}

	public static void main(String args[]) {
		System.out.print(" this is a test ");
		try {
			Class.forName("org.postgresql.Driver").newInstance();
			String url = "jdbc:postgresql://1.1.1.1/a";
			Connection con = DriverManager.getConnection(url,"b","c");
			Statement st = con.createStatement();
			String sql = "select * from testtable ";
			ResultSet rs = st.executeQuery(sql);
			while (rs.next()) {
				System.out.print(rs.getInt(1));
				System.out.println(rs.getString(2));
			}
			rs.close();
			st.close();
			con.close();

		} catch (Exception ee) {
			// System.out.print(ee.getMessage());
			ee.printStackTrace();
		}
	}
}

猜你在找的Postgre SQL相关文章