0

I have Java code that connects to an SQL server DB but I cannot access the DB from the Java app. When I compiled the connection was successfully reported but I cannot execute any SQL statement. The error is that:

run:

The SQL connection was successful.
Exception in thread "main" java.lang.ClassCastException: com.microsoft.sqlserver.jdbc.SQLServerStatement cannot be cast to java.beans.Statement
        at project.getConnection.connection(getConnection.java:73)
        at project.Main.main(Main.java:31)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

here is the line 73 if i remove the (Statement)

 s = (Statement) connection.createStatement();

1 Answer 1

3

You want to import javax.sql.Statement, not java.beans.Statement.

Sign up to request clarification or add additional context in comments.

2 Comments

sorry i run my java code after connecting to Db but i resived this error: run: The SQL connection was successful. JDBC Driver error:Invalid object name 'dbo.categories'. categories is an entity in my sql server DB thanks
@Aida That's a completely different problem. You should post it as a new question if you need help resolving it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.