Re: incompatible types?!

From: KiLVaiDeN (KiLVaiDeN_at_CaRaMaiL.CoM)
Date: 02/08/05


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



Relevant Pages

  • incompatible types?!
    ... I'm getting the error "incompatible types - found void but expected ... It uses my DataBaseConnection connection class below (this class works okay ... public class DataBaseConnection { ...
    (comp.lang.java.help)
  • Re: Illegal start of type...
    ... with a samples source CD or at least with a link to these samples on the ... > public class Hello { ... > Connection connection; ... > public void connectToDB() { ...
    (comp.lang.java.help)
  • Re: Can a ResultSet be passed back to a main program
    ... This is the class that does the connection ... public TableConnect() throws ClassNotFoundException, ... public ResultSet GetResultSet(Statement stmt, String tableName) ... public class ConnectionTest { ...
    (comp.lang.java.help)
  • Re: Getting data in class hierarchy (C#)
    ... Connection is reused while it is not being active. ... > If I want just the MoreSpecficUser data then I just call its Load() ... > public class MoreSpecficUser: User ...
    (microsoft.public.dotnet.framework.adonet)
  • Establishment of connection rejected (MySQL & Applet)
    ... The following code works as an application but not as an applet on the ... establishment of connection, message from server......Host ... I'm trying to run it from the server (localhost) and from another ... public class sqlapplet extends JApplet ...
    (comp.lang.java.databases)