Thread: Postgreslq Driver in Java & Windows

Postgreslq Driver in Java & Windows

From
"Kevin"
Date:
Hi,

I am a student who just learned Java and its JDBC capability.

I got a sample Java files which uses postgresql driver, I also got a
psqlodbc driver for Windows (2000 or XP) from:
http://gborg.postgresql.org/project/psqlodbc/genpage.php?downloads and get
it installed.

I wonder if I can run the java program in the above environment.  Below are
some sample codes extract from the sample java file.

When I run this program, I got an error like "connection rejected, please
check host and port and make sure the postmaster used the -i option when
opening the TCP/IP networking function" (This error message is originally in
Chinese).

May I know is that a setup problem and if so, how can I correct it?  Or,
must I install a Postres database?  If so, is there any trial version for
Windows?  I don't have the localhost/data_mining directory but I don't know
where should I create this directory.

Thanks very much.

Kevin.

public class DataParser {

    /**
     * put your documentation comment here
     * @param args
     */
    public static void main (String[] args) {
        Connection conn = null;
        Statement stat = null;
        Statement stat2 = null;
        if (args.length < 4) {
            System.out.println("Invalid Argument: java Class DataFile
OutFile (Confident)* (Support)*");
            return;
        }
        else {
            System.out.println("Reformating the source file");
        }
        try {
            String directory = "./";
            String fileIn = args[0];
            String fileOut = args[1];
            String replacefileOut = "result2.txt";
            File myPrimes = new File(directory, fileIn);
            Hashtable vRootTitle = new Hashtable();
            Hashtable vRootURLRef = new Hashtable();
            int seq = 0;
            DataInputStream in = new DataInputStream(new
FileInputStream(myPrimes));
            PrintWriter out = new PrintWriter(new BufferedWriter(new
FileWriter(fileOut)));
            try {
                Class.forName("org.postgresql.Driver").newInstance();
            } catch (Exception e) {
                System.err.println("Unable to load driver.");
                e.printStackTrace();
            }
            Properties pr = new Properties();
            pr.put("user", "edward");
            pr.put("password", "123456");
            conn =
DriverManager.getConnection("jdbc:postgresql://localhost/data_mining",
                    pr);
            stat = conn.createStatement();
            stat2 = conn.createStatement();



Re: Postgreslq Driver in Java & Windows

From
Doug McNaught
Date:
"Kevin" <kvhui@msn.com> writes:

> Hi,
>
> I am a student who just learned Java and its JDBC capability.
>
> I got a sample Java files which uses postgresql driver, I also got a
> psqlodbc driver for Windows (2000 or XP) from:
> http://gborg.postgresql.org/project/psqlodbc/genpage.php?downloads and get
> it installed.
>
> I wonder if I can run the java program in the above environment.  Below are
> some sample codes extract from the sample java file.
>
> When I run this program, I got an error like "connection rejected, please
> check host and port and make sure the postmaster used the -i option when
> opening the TCP/IP networking function" (This error message is originally in
> Chinese).
>
> May I know is that a setup problem and if so, how can I correct it?  Or,
> must I install a Postres database?  If so, is there any trial version for
> Windows?  I don't have the localhost/data_mining directory but I don't know
> where should I create this directory.

You need to have a PostgreSQL server to connect to.  The current
version of the server runs on Windows using the Cygwin libraries--it's
not production quality but should be fine for development work.  You
should be able to download binaries for Windows through
www.postgresql.org.

-Doug