Re: incompatible types?!
From: KiLVaiDeN (KiLVaiDeN_at_CaRaMaiL.CoM)
Date: 02/08/05
- Next message: tem2: "Re: incompatible types?!"
- Previous message: tem2: "incompatible types?!"
- In reply to: tem2: "incompatible types?!"
- Next in thread: tem2: "Re: incompatible types?!"
- Reply: tem2: "Re: incompatible types?!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 8 Feb 2005 12:53:37 +0100
"tem2" <tem2@kent.ac.uk> a écrit dans le message de
news:cua742$2h5$1@oheron.kent.ac.uk...
> I'm getting the error "incompatible types - found void but expected
> java.sql.Connection" on the line "connection =
> dbConnection.getConnection();" does anyone have any ideas why? What can I
> do to fix it?
>
> Thanks in advance.
>
> This is the code:
>
> import java.sql.*;
>
> public class createTables {
>
> private Connection connection;
> private DataBaseConnection dbConnection;
>
> public createTables() {
> dbConnection = new DataBaseConnection();
> connection = dbConnection.getConnection();
> }
>
> public void createExaminerTable() {
> String createExaminerTable = "blah blah etc";
>
> Statement create = connection.createStatement();
> create.executeUpdate(createExaminerTable);
> }
>
> It uses my DataBaseConnection connection class below (this class works
okay
> and I can connect to the database):
>
> import java.sql.*;
>
> public class DataBaseConnection {
>
> public void getConnection() {
>
> System.out.println("Trying to connect to the database.");
>
> try {
> String userId = "username";
> String password = "password";
> String driver = "org.postgresql.Driver";
> String url =
> "jdbc:postgresql://penguin.kent.ac.uk:5432/username";
>
> Class.forName(driver).newInstance();
> Connection connection = DriverManager.getConnection(url,
userId,
> password);
> Statement s = connection.createStatement();
> s.close();
> System.out.println("Connection for " + userId + " was
> successfull!");
>
> } catch (Exception e) {
> System.out.println("There was a problem connecting to the
> database.");
> System.out.println("Printing a stack trace, and exiting.");
> e.printStackTrace();
> }
> }
> }
>
>
Your getConnection method returns void. Make it return Connection... What
IDE do you use ? This would be highlighted in red all over with Eclipse,
netbeans, Jbuilder, Idea..
K
- Next message: tem2: "Re: incompatible types?!"
- Previous message: tem2: "incompatible types?!"
- In reply to: tem2: "incompatible types?!"
- Next in thread: tem2: "Re: incompatible types?!"
- Reply: tem2: "Re: incompatible types?!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|