Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

createStatement() not working

556517Nov 21 2008 — edited Nov 24 2008
Hi,

i am writing an app to connect to my mysql server and to run a simple query against it. I've managed to connect to my db fine and i am currently writing a java file called Query with the code snipet
 Connection con = DriverManager.getConnection("internet_app_design");
        Statement stmt = null;
if (con == null) {
            System.err.println("Can't connect to database");
            System.exit(0);
        }

try {
        stmt = con.createStatement();
i have all my import statements being

import com.mysql.jdbc.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

but everytime i do the stmt code, i get an error saying incompatible types but i've seen quite a few tutorial with similar stmt code e.g
http://www.stardeveloper.com/articles/display.html?article=2003091001&page=1

what should i do to rectify this?

cheers
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 22 2008
Added on Nov 21 2008
12 comments
1,476 views