안녕하세요! windows 2000 pro 에다가요
cygwin을 설치하면서 postgresql 7.4을 install 했습니다. 기본설정을
$ ipc-daemon2 --install-as-service
$ net start ipc-daemon2
$ mkdir /usr/share/postgresql/data
$ export PGDATA=/usr/share/postgresql/data
$ initdb
$ postmaster &
$ createdb mydb
$ psql mydb
mydb=# create table waether ( mydb(# city varchar(80), mydb(# temp_lo int, mydb(# temp_hi int, mydb(# prcp real, mydb(# date date mydb(# ); CREATE TABLE mydb=# insert into weather values ( 'san francisco', 46, 50, 0.25, '2003-12-26');
mydb=#\q
$
테이블만들고 insert 하고서 CLASSPATH에다가
cygwin에 설치된 C:\cygwin\usr\share\postgresql\java\postgresql.jar
를 넣어서 JDBC를 연결했고요
cygwin이 떠 있는 상태에서
import java.sql.*; public class Untitled1 {
public Untitled1() { }
public void test() {
try { String url = "jdbc:postgresql://localhost/mydb"; String user = "Administrator"; String password = "000000";
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection(url, user, password); Statement stmt = con.createStatement(); ResultSet rset = stmt.executeQuery(" select city from weather ");
System.out.println("결과 ==>> ");
if(!rset.next()) { System.out.println("Nothing!"); } else { String show = rset.getString(1); System.out.println("->> "+show); }
if(rset != null) rset.close(); if(stmt != null) stmt.close(); if(con != null) con.close(); } catch(Exception e) { System.out.println(e.getMessage()); }
} public static void main(String[] args) throws Exception { Untitled1 untitled11 = new Untitled1(); untitled11.test(); } }
를 실행하니까
Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
이렇게 에러가 나더라고요!
설정을 어느 부분이 잘못된 것인지 좋은 답변 부탁드립니다.
그리고 cygwin을 언제나 띄워놓아야 하는건지? 이미 서비슨느 돌고 있는데
그것도 궁금해요!
즐거운 연말 보내세요
|