Forums Register Login

Can't get right results from a query

+Pie Number of slices to send: Send
Hi all,

i have developed a stand alone program that runs from the command line. this program connects to the mysql database but the results it returns are not right. i need your help on how best i can refactor the following code to provide the right results because this query should return all the firstnames in the database students.

private void prepareStatements( Connection dbConnection ) throws SQLException
{
System.out.println( "\nPreparing Statements.....");
changeFirstname = dbConnection.prepareStatement("SELECT firstname from students");

System.out.println( changeFirstname );
[ January 20, 2005: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
Hmm. I suspect you need to execute the PreparedStatement then process the ResultSet to see the results. What you are doing is creating a PreparedStatement, then writing that PreparedStatement out to standard output. This is the equvalent of calling PreparedStatement.toString();
I'd look again at the PreparedStatement class JavaDocs to see how you get a ResultSet from it. (You might also consider looking at the JDBC tutorial at Sun if you haven't already.)
+Pie Number of slices to send: Send
Please clarify what do mean by right results becos the select statement fetches all the first names available in the student table.
+Pie Number of slices to send: Send
executing the prepared statement and iterating through the rows


ResultSet rs = null;
rs = changeFirstname.executeQuery();

while (rs.next()) {
//process the data
}
+Pie Number of slices to send: Send
Moving this to the JDBC forum.
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 738 times.
Similar Threads
Replacing name with first character in the DB (code included)
parser integer to string
JDBC doesn't retrieve all the results available in the MSSQL database
Tomcat 6 and catche problem
Query Result Caching
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:44:33.