日期:2014-05-20 浏览次数:20810 次
package traffic; import java.sql.*; public class TrafficDatabaseCore { static void getConnection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException { Class.forName("org.postgresql.Driver").newInstance(); Connection conn; conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/traffic", "postgres", "******"); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select * from test"); while(rs.next()) { System.out.print(rs.getString(0)); System.out.println(rs.getInt(1)); } } }