I'm trying to connect a DB from Postgres with a program in Java. I'm including this code:

Class.forName(driver);
Connection con = DriverManager.getConnection(connectString, user , password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM students");

But I'm getting this erros in Statemen and stmt.excuteQuery:
With Statement: incompatible types. Required: java.beans.Statement. Found: java.sql.Statement
With .executeQuery: Cannot find symbol. Symbol: method executeQuery (java.lang.String). Location: class java.beans.Statement

In all the tutorials they include this code and they don't seem to have any problem. Any idea what can I do?

Recommended Answers

All 3 Replies

What "using" statements do you have?

I've this "imports"

import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

The import java.beans.Statement is wrong . You have to import java.sql.Statement .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.