Michael Birkmose wrote:
>
> Hej gruppe,
> Jeg har et problem med JDBC/postgresql. Er der nogle der kan sige hvorfor
> nedenstående kaster en ClassNotFoundException?
Fordi din postgres specifikke klasse ikke er under import.
Noget a la import postgres.jdbc.driver.*;
Mvh Morten
> Jeg har fint kompileret nedenstående med en class path til min postgressql
> JDBC driver (postgres.jar). Postgresserveren er også startet.
>
> import java.io.*;
> import java.sql.*;
> import java.text.*;
>
> public class basic
> {
>
> public static void main (String[] args) throws
> ClassNotFoundException,SQLException
> {
>
> Class.forName("postgresql.Driver");
>
> Connection db; // The connection to the database
> Statement st; // Our statement to run queries with
>
> String url = "jdbc:postgresql:mindatabase" ;
> String usr = "minbruger";
> String pwd = "password";
> System.out.println("Connecting to Database URL = " + url);
>
> db = DriverManager.getConnection(url, usr, pwd);
> System.out.println("Connected...Now creating a statement");
> st = db.createStatement();
>
> ResultSet rs = st.executeQuery("select * from tabel");
> while(rs.next())
> {
> System.out.print("Column 1 returned ");
> System.out.println(rs.getString(1));
> }
> rs.close();
> st.close();
>
> }
> }
>
> --
> --
> Michael Birkmose, stud. polyt
> Aalborg University, Dept. of Electronics and Information Technology
> Badehusvej 13, DK-9000 Aalborg, Denmark
--
Morten Primdahl Caput A/S Tel +45 70 12 24 42
morten@caput.com Nygade 6 Fax +45 70 11 24 42
http://www.caput.com/ DK-1164 Kbh K