Oppure

Loading
04/06/10 18:35
Antetemp0
Ciao a tutti!!Ho istallato eclipse e postgresql.Ho scaricato il driver di postgres e l'ho messo dentro il mio classpath.Dopo di che ho creato il mio server postgres all'interno di eclipse, mettendo i dati di accesso e impostando come driver quello che ho scaricato.Ho creato una tabella clienti su postgres una classe PersistenceException,una cliente ed una dataSource :
public class Cliente 
{
	private int id_cl;
	private int codice_cliente;
	private String nome;
	private String cognome;
	private String indirizzo;
	
	
	
	

	public int getId_cl() {
		return id_cl;
	}

	public void setId_cl(int c)  {
		this.id_cl=c;
	}

	public int getCodice_cliente() {
		return codice_cliente;
	}

	public void setCodice_cliente(int codiceCliente) {
		codice_cliente = codiceCliente;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getCognome() {
		return cognome;
	}

	public void setCognome(String cognome) {
		this.cognome = cognome;
	}

	public String getIndirizzo() {
		return indirizzo;
	}

	public void setIndirizzo(String indirizzo) {
		this.indirizzo = indirizzo;
	}


	
}

mport java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DataSource 
{
	
	public String dbURI = "jdbc:postgresql://localhost/Prova:5432";
	public String userName = "postgres";
	public String password = "kaos83";
	
	public Connection getConnection() throws PersistenceException
	{
		Connection connection;
		try
		{
			Class.forName("org.postgresql.Driver");
			connection = DriverManager.getConnection("dbURI,userName,password");
		}
		catch (ClassNotFoundException e) {
			throw new PersistenceException(e.getMessage());
		} catch(SQLException e) {
			throw new PersistenceException(e.getMessage());
		}
		return connection;
	}
}

ublic class PersistenceException extends Exception {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3835068319580102263L;

	public PersistenceException(String msg){
		super(msg);
	} 
	
}

mport java.sql.*;


public class Main 
{
public static void main (String [] args) throws PersistenceException

{
	Connection connection = null;
	PreparedStatement statement = null;
	DataSource ds = new DataSource();
	Cliente c = new Cliente();
	c.setCodice_cliente(1);
	c.setCognome("rossi");
	c.setId_cl(2);
	c.setIndirizzo("ciao");
	c.setNome("marko");
	
	String query ="INSERT into clienti(codice_cliente,nome,cognome,indirizzo,id_cl) VALUES (?,?,?,?,?)";
	try 
	{
		connection=ds.getConnection();
		statement = connection.prepareStatement(query);
		statement.setInt(1, c.getCodice_cliente());
		statement.setString(2, c.getNome());
		statement.setString(3, c.getCognome());
		statement.setString(4,c.getIndirizzo());
		statement.setInt(5,c.getId_cl());
		statement.executeUpdate();
	}
	catch (SQLException e)
	{
		throw new PersistenceException(e.getMessage());
	}
	finally
	{
		try
		{
			if(statement!=null)
				statement.close();
			if(connection!=null)
				connection.close();
		}
		catch (SQLException e)
		{
			throw new PersistenceException (e.getMessage());
		}
	
	}
}
}



l'errore che mi da è questo:
Exception in thread "main" PersistenceException: org.postgresql.Driver
    at DataSource.getConnection(DataSource.java:22)
    at Main.main(Main.java:22)
cosa sbaglio?Grazie
aaa