废话不多说,RT~
首先简单看一下数据库中的数据:
下面是Java测试类的代码:
package com.wl.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; public class Test { public static void main(String[] args) { try { Class.forName("org.postgresql.Driver").newInstance(); String url = "jdbc:postgresql://localhost:5432/testdb"; Connection con = DriverManager.getConnection(url, "postgres", "111111"); Statement st = con.createStatement(); String sql = " select * from t_user "; ResultSet rs = st.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); while (rs.next()) { for (int i = 1; i <= columnCount; i++) { System.out.print(rs.getString(i) + "\t"); } System.out.println(); } rs.close(); st.close(); con.close(); } catch (Exception e) { System.out.print("exception:" + e.getMessage()); } } }
<!-- postgresql --> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.3-1102-jdbc4</version> </dependency>
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/wlwlwlwl015/article/details/48131073