Error in createStatement() "incompatible types"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • beso2ooo
    New Member
    • Nov 2012
    • 4

    Error in createStatement() "incompatible types"

    im trying to connect to the database and thier is an error in the createstatemnet thats is "incompatab le types required is java.beans.Stat emnet and found java.sql.Statem ent "
    any one can help me in this error
    thanx .

    Code:
      static Connection connection;
                static Statement statement;
                
                
                
                public static void SetupConn(){
            
        try {
          // Step 1: Load the JDBC driver.
          Class.forName("org.hsqldb.jdbcDriver");
          System.out.println("Driver Loaded.");
          // Step 2: Establish the connection to the database.
          String url = "jdbc:hsqldb:data/tutorial";
    
          connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
          System.out.println("Got Connection.");
    
          statement = connection.createStatement();
        } catch (   ClassNotFoundException | SQLException e) {
          System.err.println("Got an exception! ");
          System.exit(0);
        }
      }
                
    }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    The error message is fairly clear, your statement variable is a java.beans.stat ement while connection.crea teStatement() returns a java.sql.statem ent. You should create your statement variable as a java.sql.statem ent type.

    Comment

    Working...