从小就学习不好

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

java连接PostgreSql

各版本地址:https://mvnrepository.com/artifact/postgresql/postgresql/<!-- https://mvnrepository.com/artifact/postgresql/postgresql -->

<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>



写个jdbc,进行连接,运行报错。

org.postgresql.util.PSQLException: ������������: ��������� "runoobdba" ���������
at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:469)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:112)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at aa.ConnUtil.getConn(ConnUtil.java:18)
at aa.TestMain.main(TestMain.java:16)
Exception in thread "main" java.lang.NullPointerException
at aa.TestMain.main(TestMain.java:22)

 

原因:

 

url地址后面的数据库名称写错了。字符串书写的时候一定要注意再注意。 

 

posted on 2020-03-16 17:13  从小就学习不好  阅读(482)  评论(0编辑  收藏  举报