質問編集履歴
1
コード、エラー文のテキスト化
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,55 @@
|
|
1
1
|
コマンドプロンプトでJavaからPostgreSQLへの接続ができません
|
2
2
|
DBConnect1.javaファイルを使用していており、コンパイルはできるのですがJDBCドライバのファイルを指定して実行ができません。
|
3
|
+
``` DBConnect.java
|
4
|
+
import java.sql.*;
|
5
|
+
|
6
|
+
public class DBConnect1 {
|
7
|
+
public static void main(String[] args) throws Exception {
|
8
|
+
Connection con;
|
9
|
+
Statement st;
|
10
|
+
ResultSet rs;
|
11
|
+
|
12
|
+
String url = "jdbc:postgresql://localhost:5432/postgres";
|
13
|
+
String user = "postgres";
|
14
|
+
String password = "test";
|
15
|
+
|
16
|
+
Class.forName("org.postgresql.Driver");
|
17
|
+
|
18
|
+
con = DriverManager.getConnection(url, user, password);
|
19
|
+
st = con.createStatement();
|
20
|
+
|
21
|
+
rs = st.executeQuery("SELECT 1 AS col_1");
|
22
|
+
|
23
|
+
rs.next();
|
24
|
+
System.out.print(rs.getInt("col_1"));
|
25
|
+
|
26
|
+
rs.close();
|
27
|
+
st.close();
|
28
|
+
con.close();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
```error
|
34
|
+
C:\PostgreSQL\java\src>C:\PostgreSQL\java\jdk\bin\java -cp C:\PostgreSQL\jdbc\*;. DBConnect1
|
35
|
+
Exception in thread "main" org.postgresql.util.PSQLException: 接続試行は失敗しました。
|
36
|
+
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:262)
|
37
|
+
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:67)
|
38
|
+
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:216)
|
39
|
+
at org.postgresql.Driver.makeConnection(Driver.java:406)
|
40
|
+
at org.postgresql.Driver.connect(Driver.java:274)
|
41
|
+
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
|
42
|
+
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:229)
|
43
|
+
at DBConnect1.main(DBConnect1.java:15)
|
44
|
+
Caused by: java.io.IOException: UTF-8シーケンス違反: 初期バイトは、10xxxxxx: 130
|
45
|
+
at org.postgresql.core.UTF8Encoding.decode(UTF8Encoding.java:104)
|
46
|
+
at org.postgresql.core.PGStream.ReceiveString(PGStream.java:331)
|
47
|
+
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:429)
|
48
|
+
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:208)
|
49
|
+
... 7 more
|
50
|
+
```
|
51
|
+
|
52
|
+
|
3
53
|

|
4
54
|
|
5
55
|

|