I am browsing this website for quite some time now. The community helped me quite a lot, even though I never registered. Thanks for that.
However, this time I can't find a solution to my problem just by browsing, so I decided to register here and state my question so that someone might be able to help me.
First of all I'd like to say, that I'm basically at the beginning of my studies, so I'm not very knowledgeable yet. At the moment I'm learning for a upcoming exam and I need to know about databases. The Database of choice is Postgresq. But to really understand something like that, you need to try it out and not just read about it.
I'm not exactly sure what information are exactly required. But I'm using Windows 7, pgadmin and eclipse for that, all of them should be up to date. If you need further information, please ask for it.
I used a Tutorial to get it up and running, however I'm not able to establish a connection to the database using eclipse. The DriverManager.getConnection() causes a UTF-8 error I'm not understanding nor able to fix it.
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:280)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:67)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:212)
at org.postgresql.Driver.makeConnection(Driver.java:407)
at org.postgresql.Driver.connect(Driver.java:275)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.hywy.TestConnection.main(TestConnection.java:23)
Caused by: java.io.IOException: Illegal UTF-8 sequence: initial byte is 11111xxx: 252
at org.postgresql.core.UTF8Encoding.decode(UTF8Encoding.java:131)
at org.postgresql.core.PGStream.ReceiveString(PGStream.java:331)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:447)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:223)
... 7 more
The Code I'm using is:
import java.sql.*;
import java.util.Properties;
//import com.hywy.db.DbContract;
public class TestConnection {
public static void main(String[] args) {
Properties properties = new Properties();
properties.setProperty("user", "postgre");
properties.setProperty("password", "random_password");
//properties.setProperty("ssl", "true");
String url = "jdbc:postgresql://localhost:1112/people";
try {
Class.forName("org.postgresql.Driver");
// Connection c = DriverManager.getConnection(
// DbContract.HOST+DbContract.DB_NAME,
// DbContract.USERNAME,
// DbContract.PASSWORD);
Connection con = DriverManager.getConnection(url, properties);
//Connection c = DriverManager.getConnection("jdbc:postgresql://localhost:1112/people" , "postgre" , "random_password");
System.out.println("DB connected");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
}
The code is a bit of a mess, since I Googled some time for it and tried some stuff. I was not sure if I should paste the out-commented code with the rest of it, but at least you can see that I already tried some things. I also tried a different port, at first I was using the standard port (5432) but it made no difference.
I also linked the up-to-date jdbc jar file in my build path.
I hope someone knows (about) this problem and is willing to help me. Thanks in advance.
Excuse my English, it's not my native tongue.
postgresql-9.4.1209.jarand my JDK 1.7 JVM. I tested the version9.4-1206-jdbc42and every thing is okay. What JDK version you are using ?