Advertisement
Guest User

Untitled

a guest
Jan 14th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided.
  2. at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:473)
  3. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:203)
  4. at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
  5. at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:159)
  6. at org.postgresql.Driver.makeConnection(Driver.java:416)
  7. at org.postgresql.Driver.connect(Driver.java:283)
  8. at java.sql.DriverManager.getConnection(Unknown Source)
  9. at java.sql.DriverManager.getConnection(Unknown Source)
  10. at com.test.dao.java.TestDao.getConnection(TestDao.java:37)
  11. at com.test.dao.java.TestDao.getTest(TestDao.java:61)
  12. at com.test.main.java.TestMain.main(TestMain.java:33)
  13.  
  14. @Component
  15. public class TestDao {
  16. static PreparedStatement ps;
  17. ResultSet rs;
  18. Connection conn= null;
  19.  
  20. /**
  21. * @return
  22. * @throws SQLException
  23. * @throws ClassNotFoundException
  24. */
  25. private Connection getConnection() throws SQLException, ClassNotFoundException,FileNotFoundException,NullPointerException{
  26.  
  27.  
  28. if(conn==null)
  29. {
  30. try {
  31. Class.forName("org.postgresql.Driver");
  32. conn = DriverManager.getConnection(
  33. "jdbc:postgresql://localhost:5432/testdb?user=postgres & password=postgres");
  34. conn.close();
  35. }
  36. catch(Exception e) {
  37. e.printStackTrace();
  38.  
  39. }
  40. }
  41. return conn;
  42.  
  43.  
  44. }
  45.  
  46. /**
  47. * @param testId
  48. * @return
  49. * @throws SQLException
  50. * @throws ClassNotFoundException
  51. * @throws NullPointerException
  52. * @throws FileNotFoundException
  53. */
  54. public Test getTest(int testId) throws SQLException, ClassNotFoundException, FileNotFoundException, NullPointerException {
  55.  
  56. conn = getConnection();
  57. try {
  58.  
  59. conn = getConnection();
  60. ps =conn.prepareStatement("SELECT * FROM testdb.testtab where id =?");
  61. ps.setInt(1, testId);
  62. Test test =null;
  63. rs = ps.executeQuery();
  64. if(rs.next())
  65. {
  66. test = new Test(testId, rs.getString("name"));
  67. }
  68.  
  69. return test;
  70. }
  71. finally
  72. {
  73. rs.close();
  74. ps.close();
  75. conn.close();
  76. }
  77.  
  78.  
  79. }
  80. }
  81.  
  82. <?xml version="1.0" encoding="UTF-8"?>
  83. <beans xmlns="http://www.springframework.org/schema/beans"
  84. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  85.  
  86. xsi:schemaLocation="http://www.springframework.org/schema/beans
  87. http://www.springframework.org/schema/beans/spring-beans.xsd
  88. http://www.springframework.org/schema/context
  89. http://www.springframework.org/schema/context/spring-context.xsd "
  90.  
  91. xmlns:context="http://www.springframework.org/schema/context">
  92. <!-- <context-annotation-config/> -->
  93. <context:component-scan base-package="com.test.dao"/>
  94. </beans>
  95.  
  96. DriverManager.getConnection("jdbc:postgresql://localhost:5432/testdb", "postgres","postgres");
  97.  
  98. DriverManager.getConnection("jdbc:postgresql://localhost:5432/testdb?user=postgres & password=postgres & ssl=true";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement