Results 1 to 1 of 1
- 04-15-2010, 09:01 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
return output from a non select query (java/access)
I'm trying to return my entire database as a result of the following..but i'm not getting any results back..I also want to clear the text area/field once result are returned..
I have attached my java and database files.
Here is the code below where I am having the challenge. If enter "select * from students" then it will return something, but if i do anything else, it wont return anything.
public String query(String query){
String output = "";
String[] temp = query.split(" ");
try{
if(!temp[0].equalsIgnoreCase("select")){
statement.executeUpdate(query);
//query("SELECT * FROM students");
return output;
}
else{
resultSet = statement.executeQuery(query);
output = formatResult();
return output;
}
}
catch(SQLException sqle){
JOptionPane.showMessageDialog(null, sqle);
}
return output;
}
private String formatResult(){
String output = "";
try{
while(resultSet.next()){
output += resultSet.getString("Fname") + " " +
resultSet.getString("Lname") + " " +
resultSet.getInt("Age") + "\n";
}
}
catch(SQLException sqle){
System.err.print(sqle);
}
return output;
}Last edited by kitiaradl; 04-20-2010 at 05:48 PM. Reason: attachment
Similar Threads
-
Java Native Access (JNA) return types of void *
By burnumd in forum Advanced JavaReplies: 5Last Post: 01-15-2010, 12:09 AM -
MySQL/JDBC Prepared Statement Select query
By thelinuxguy in forum Advanced JavaReplies: 4Last Post: 02-12-2009, 05:29 PM -
SELECT FROM WHERE query
By herfnai in forum JDBCReplies: 3Last Post: 11-24-2008, 11:04 AM -
problem in select query
By herfnai in forum JDBCReplies: 0Last Post: 08-17-2008, 11:47 AM -
Using a variable in a SELECT FROM WHERE query
By cplmckenzie in forum JDBCReplies: 12Last Post: 04-23-2008, 03:24 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks