mardi 21 juillet 2015

SQLite general getEntry(...) function

I'm on a Java Project and programming a SQLite "Actionhandler-Class" where you can create/drop tables and add/update/get/delete Entry's in these tables.

The general creating/dropping of tables and the adding of an Entry works fine, but now I want to make the getEntry(...) function.

public void getEntry(String table, String[] ident){
    try{
        stmt = conn.createStatement();
        String exec = "SELECT " + ident[0] + " FROM " + table;
        if(!ident[1].isEmpty()){
            exec += " WHERE(" + ident[1] + ");";
        }else{
            exec += ";";
        }
        ResultSet res = stmt.executeQuery(exec);
        while(res.next()){
            System.out.println(res.getInt("uid"));
            System.out.println(res.getString("uname"));
            System.out.println(res.getString("pwd"));
            System.out.println(res.getString("mail"));
            System.out.println(res.getInt("rank"));
            System.out.println(res.getInt("coins"));
            System.out.println(res.getString("stg"));
        }
        res.close();
        stmt.close();
    }catch(Exception e){
        e.printStackTrace();
    }
}

This works, of course! But I dont want to System.out.println(...) all Data, I want to give it back to the main(...) function which called the getEntry(...) function so it can work with this Data. How to give the res data back of this function?

Aucun commentaire:

Enregistrer un commentaire