jdbc postpresql 编程 (一)



import java.sql.*;

import javax.naming.directory.DirContext;
public class test {

	public static void main(String[] arg)
	{
		String driver="org.postgresql.Driver";

		String url="jdbc:postgresql://localhost:5432/postgres"; 
		String user="test";
		String pwd="test";
		try {
			Class.forName(driver);
			System.out.println("Successfully load driver");

			Connection connection=DriverManager.getConnection(url,user,pwd);
			System.out.println("Successfully connect");

			Statement statement=connection.createStatement();

			ResultSet rs=statement.executeQuery("select * from test");

			while (rs.next()) { 
	              System.out.print(rs.getString(1)); 
	              System.out.print("  "); 
			} 
			rs.close(); 
			statement.close(); 
			connection.close(); 

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}








你可能感兴趣的:(jdbc postpresql 编程 (一))