Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org.postgresql.util.PSQLException: The server requested password-based authentication, but no password was provided.
- at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:473)
- at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:203)
- at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
- at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:159)
- at org.postgresql.Driver.makeConnection(Driver.java:416)
- at org.postgresql.Driver.connect(Driver.java:283)
- at java.sql.DriverManager.getConnection(Unknown Source)
- at java.sql.DriverManager.getConnection(Unknown Source)
- at com.test.dao.java.TestDao.getConnection(TestDao.java:37)
- at com.test.dao.java.TestDao.getTest(TestDao.java:61)
- at com.test.main.java.TestMain.main(TestMain.java:33)
- @Component
- public class TestDao {
- static PreparedStatement ps;
- ResultSet rs;
- Connection conn= null;
- /**
- * @return
- * @throws SQLException
- * @throws ClassNotFoundException
- */
- private Connection getConnection() throws SQLException, ClassNotFoundException,FileNotFoundException,NullPointerException{
- if(conn==null)
- {
- try {
- Class.forName("org.postgresql.Driver");
- conn = DriverManager.getConnection(
- "jdbc:postgresql://localhost:5432/testdb?user=postgres & password=postgres");
- conn.close();
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- return conn;
- }
- /**
- * @param testId
- * @return
- * @throws SQLException
- * @throws ClassNotFoundException
- * @throws NullPointerException
- * @throws FileNotFoundException
- */
- public Test getTest(int testId) throws SQLException, ClassNotFoundException, FileNotFoundException, NullPointerException {
- conn = getConnection();
- try {
- conn = getConnection();
- ps =conn.prepareStatement("SELECT * FROM testdb.testtab where id =?");
- ps.setInt(1, testId);
- Test test =null;
- rs = ps.executeQuery();
- if(rs.next())
- {
- test = new Test(testId, rs.getString("name"));
- }
- return test;
- }
- finally
- {
- rs.close();
- ps.close();
- conn.close();
- }
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context.xsd "
- xmlns:context="http://www.springframework.org/schema/context">
- <!-- <context-annotation-config/> -->
- <context:component-scan base-package="com.test.dao"/>
- </beans>
- DriverManager.getConnection("jdbc:postgresql://localhost:5432/testdb", "postgres","postgres");
- DriverManager.getConnection("jdbc:postgresql://localhost:5432/testdb?user=postgres & password=postgres & ssl=true";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement