This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

How to use jdbc? (with attachement)


Woops forgot to attach the file, sorry for the repeat. --adrian


Hey everyone,

I'm trying out jdbc. I finally got the program working using sun's java
but I don't like it, I'd rather be Free. :-)


I have a program (attached). When I do the following:

1) setenv PATH /usr/local/gcc3_0/bin:$PATH
   setenv LD_LIBRARY_PATH /usr/local/gcc3_0/lib/
2) gcj --main=DatabaseTester.java -o DatabaseTester DatabaseTester.java 

I get:

/home/acuster/tmp/ccuuonhUmain%O: In function `main':
/home/acuster/tmp/ccafMTcVmain.i(.text+0x1a): undefined reference to
`DatabaseTester::java::class$'
collect2: ld returned 1 exit status

I tried copying the postgres .jar file into /usr/local/gcc3_0/share/lib/
but that didn't help. I tried a bunch of other stuff. If anyone has a
good example of how one can set up the compiler, userProgramme, Database
to get them working together, please let me know.

Thanks for any info,
adrian
acuster@nature.berkeley.educational

/////////////////////////////////////////
//      This is DatabaseTester.java   //
////////////////////////////////////////



import java.sql.*;

public class DatabaseTester{


	public static void main(String[] args) {

		System.out.println("Start the program...");

		try {
			Class.forName("org.postgresql.Driver");

			String sourceURL = new
			String("jdbc:postgresql://tsetse.lab-net:5432/avcfirst");

			Connection myConnection = DriverManager.getConnection(
				sourceURL, "netuser","askTheBase");
			Statement myStatement = myConnection.createStatement();
			ResultSet myResultSet = myStatement.executeQuery("Select * from netable");
			
			while (myResultSet.next() ) {
				System.out.println(myResultSet.getString("city"));
			}
		} catch(ClassNotFoundException e) {
			System.out.println("The class wasn't found.");
		} catch(SQLException e) {
			System.out.println("An SQL exception occured.");
		}
	}
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]