无法从postgresql检索数据

时间:2015-01-09 14:47:01

标签: java postgresql jdbc

这是我连接postgresql数据库的连接字符串。使用此代码我可以连接db

connection = DriverManager.getConnection(
                    "jdbc:postgresql://127.0.0.1:5433/Test", "youtube",
                    "1");

然后我使用相同的代码来检索一些数据。我得到了这个异常

org.postgresql.util.PSQLException: ERROR: "userdetail" NOT EXIST
  Position: 27

引用此行

con=GetDbConn();

所以mytable表名是UserDetail而不是userdetail我不明白为什么我收到此异常消息

这是我的代码

public class DbUtils {

    private static final String DB_DRIVER="org.postgresql.Driver";
    private static final String DB_CONN="jdbc:postgresql://127.0.0.1:5433/Test";
    private static final String DB_USER="youtube";
    private static final String DB_PASS="1";

    public  void  SelectUserDetails() {
        Connection con=null;
        Statement statement;
        String query="select isim,soyisim  from UserDetail";

        try {
            con=GetDbConn();
            statement= con.createStatement();
            ResultSet resultSet=statement.executeQuery(query);

            while(resultSet.next()){

                String isimM=resultSet.getString("isim");
                String soyisimM=resultSet.getString("soyisim");
                System.out.println("isim :"+soyisimM+" soyisim: "+soyisimM);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
        e.printStackTrace();
        }


    }

    private static Connection GetDbConn() {

          Connection con = null;
        try {
            Class.forName(DB_DRIVER);
            con=DriverManager.getConnection(DB_CONN, DB_USER, DB_PASS);



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

        } catch (SQLException e) {
            e.printStackTrace();
        }
        return con;


    }
}

0 个答案:

没有答案