当前位置: 代码迷 >> J2SE >> 使用jdbc查询postgres数据库遇到有关问题
  详细解决方案

使用jdbc查询postgres数据库遇到有关问题

热度:199   发布时间:2016-04-24 01:18:07.0
使用jdbc查询postgres数据库遇到问题
Java code
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));        }    }    }



出现异常:org.postgresql.util.PSQLException: 栏位索引超过许可范围:0,栏位数:1。


我使用查询语句"select * from test"在SQL SHELL中查询可以得到正确结果:
  test_str | test_int
----------------------+----------
 0943111196 | 120
(1 行记录)

------解决方案--------------------
列数是从"1"开始的,不能从"0"开始.
  相关解决方案