last day (15 days later) » 

9:10 PM
1
A: SQLite general getEntry(...) function

FevPlrYou can return the function as ResultSet instead : public ResultSet getEntry(String table, String[] ident){ try{ stmt = conn.createStatement(); String exec = "SELECT " + ident[0] + " FROM " + table; if(!ident[1].isEmpty()){ exec += " WHERE(" + ident[1] + ");";...

 
Yeah, but where should i close stmt and res then, and where should i close the conn?
 
wait, let me modify it. according to your structure
 
Do you need more of my src?
 
@MartinFischer, see my latest update above.
 
Okay. And must stmt be closed after all operations on res?
 
9:10 PM
Yes. @MartinFischer,(but in case you need to reuse the stmt then just close the res) Btw this is the last comment allowed, but feel free to accept my answer if it helps solves the problem, so I know this sweat is not wasted uselessly, but it's up to you.
 
Mustn't I also close the yourInstance.res.close() AND tempResultSet.close() ?
Can I please just ask you one question more in chat? Can you invite me to chat pls?
Hello. Please join the chat room!
 
In your code , stmt created connection object, while res is the one executing the query , so closing res doesn't mean closing stmt, imagine you want to still use the stmt for different rs object for exact query in that case you just need close res, you'll close everthing just after you don't need them anymore ;)
@MartinFischer, hey hello mate?? I'm here
 
What is unclear?
let me repeat :
In your code , stmt created statement of connection object, while res is the one executing the statement ( with query) , so closing res doesn't mean closing stmt, imagine you want to still use the stmt for different rs object , in that case you just need close res, you'll close everthing just after you don't need them anymore ;)
 
can you please check if i closed every ResultSet, Statement and Connection correctly now? gist.github.com/anonymous/dfba2bc28dd698863bd4
 
9:16 PM
let me see
 
yes , they are closed well..
assuming like thing:
 
at every possible ending and function? yes? also if i enter "stop"?
 
stmt = conn.createStatement(); <--- create new statement object
stmt.executeUpdate('DELETE FROM '); <-- close statement for delete


stmt = conn.createStatement(); <--- create new statement object
stmt.executeUpdate('INSERT INTO '); <-- close statement for insert


// THIS IS SPECIAL CASE FOR SELECT
stmt = conn.createStatement();
ResultSet rs= stmt.executeUpdate();

stmt.close();<-- close statement for select
rs.close() <-- streams where rows retrieved from db
But of course you can make it a single entry from stmt , so you don't have to call it multiple times
alternative would be
public function createStatement (){}
 
okay. And must i close just the ResultSet which is returned by the function, so which i created in my main program or also the ResultSet in the function which is returned?
 
9:26 PM
YES
SINCE YOU DON"T WANT TO PROCESS THAT res anymore right??
 
and how can i close the rreturned one?
 
You've don't by res.close();
You HAVE DONE IT , res.close();
at LINE 64
 
thats in my server.java
and how in line 80 in sqldb.java?
 
You're start confusing , look
CLOSE res from ResultSet res = db.getEntry("users", new String[] {"*", "uname = 'Martin'"}); MEANS CLOSE the res FROM THE FUNCTION, SINCE THE FUNCTION RETURNS the res
 
ahh yeah ofc, sorry
i was confused from all these closings :D
yeah thanks!
enjoy the evening, cya!
 
9:36 PM
WAIT!!
WAIT!!!
I GET YOUR PROBLEM!!!
 
wait
public ResultSet 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);
return res;
}catch(Exception e){
e.printStackTrace();
}
return null;
}
change to public ResultSet getEntry(String table, String[] ident) throws SQLException {
ResultSet res =null;

try{
stmt = conn.createStatement();
String exec = "SELECT " + ident[0] + " FROM " + table;
if(!ident[1].isEmpty()){
exec += " WHERE (" + ident[1] + ");";
}else{
exec += ";";
}
res = stmt.executeQuery(exec);
return res;
}catch(Exception e){
e.printStackTrace();
}
return res;
it's not necessary actually just to improve your code style..
 
can you wait 10 mins pls?
 
ok
@MartinFischer, Exception is for UNIVERSAL EXCEPTION , use SQLException Instead, CHANGE EVER catch(Exception e) to catch(SQLException e)
Don't worry I'm still here, drinking some coffee
 
9:57 PM
im back
okay. but every opened thng is closed correctly now?
 
yes..
I'm pretty sure, could you tell me more about the project, is this college stuff??
 
before i tell you, just one more question: is it important to close all opened stuff?
 
yes because the values from db are transmitted with something called stream, you need to close to prevent some collision
 
ahh ok
 
except for the 'stmt', close means close the statement connection
don't forget to change every catch(Exception e) to catch(SQLException e)
 
10:04 PM
so this project is my first software-only project. normally im building robotics or other electronic stuff and programming the microcontrollers in C. but this time i want to do some software and so im making with a friend who is good at webdesign and webdevelopment a game similar to habbo.com, im making the server in java
 
Uh I see ,
 
yeah
btw
 
I case you get a problem (assuming still around my knowledge), you can see me email at pepthunder@gmail.com , but of course I couldn't promise
*in case
 
could i add you in any instant messageing service pls?
 
read above
 
10:06 PM
ahh cool
thx
 
oke mate see ya..
 
yeah, cya, byebye
 

last day (15 days later) »