Unable to create SQL Statement - Java

Well, writing down the login for the game and switching from C # to java. The problem is that I use the old code as exmaple, but I continue to encounter this problem when creating a statement from the connection. I get the symbol "createStatement () not found". Is there a new way to do SQL statements or is there something else wrong?

Here is the source code.

import java.sql.*;

public class SQLCheck {

    public Connection con;
    public void connect(){
        String host = "somewhereoutthere";
        String username = "stuff";
        String pass = "haclmolg";
        String db = "users";

        try{
            Class.forName("com.mysql.jdbc.Driver");
            String connectionUrl = "jdbc:mysql://"+host+"/"+db+"?";
            con = (Connection) DriverManager.getConnection(connectionUrl,username,pass);
            System.out.println("Server: Connected to MYSQL");
        } catch(SQLException e){
            System.out.println("Server: SQL EXECEPTION: " + e.toString());
        } catch (ClassNotFoundException cE){
            System.out.println("Server: Class not found: " + cE.toString());
        }
    }
    boolean checkLogin(String userName, String password){
        boolean correct = false;

        Statement s = con.createStatement();
    }
}
+3
source share
2 answers

You should not reuse the name Connectionfor your own class. When you declare type objects Connection, you are not using SQL code, you are using your own.

, con, tanksgrid.Connection, java.sql.Connection. . con.createStatement(), Connection, , .

EDIT:

- : SQLException, , createStatement(). (, .) Eclipse .

+7

. , con Connection.

Connection MyConnection, - con java.sql.Connection con;. , , (Connection) (java.sql.Connection)

+2
source

All Articles