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();