1 Replies - 785 Views - Last Post: 15 May 2013 - 02:01 AM Rate Topic: -----

#1 spark29  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 26-November 12

database query result

Posted 14 May 2013 - 10:59 PM

Hey guys please help me with assignment

Write a java program to query the StockTracker database for all users and all stocks held by each user. List the user's ID, first name and last name followed by their stocks including both the stock symbol and stock description(name). This can be a console applicaton that produces output to the screen. Use the project StockTrackers to add additional users and stocks. If necessary for an extra challenge use only the StockTracker DB data access class to obtain data from the database

This is my coding please check what I'm doing wrong, it compiles fine but i get this error:

Exception in thread "main" java.sql.SQLException: No suitable driver found for S
at java.sql.DriverManager.getConnection(DriverManager.java:604)
at java.sql.DriverManager.getConnection(DriverManager.java:243)
at Query.<init>(Query.java:16)
at Query.main(Query.java:39)
Press any key to continue . . .

import java.sql.*;
import java.io.*;
import java.util.*;

public class Query
	String userID;
	String firstName;
	String lastName;
	String symbol;

	public Query() throws Exception
		String url = "jdbc:odbc:StockTracker";
		Connection con = DriverManager.getConnection(url);
		Statement stmt = con.createStatement();

		System.out.println("Stock holdings by User\n");
		System.out.println("User ID User Name\n");
		System.out.println("Stock - Description\n");

		ResultSet rs = stmt.executeQuery("SELECT * FROM Users");
		ResultSet rs = stmt.executeQuery("SELECT u.userID, firstName, s.symbol, symbolName, FROM users AS iJOIN userstocks AS us ON u.userid = us.userid JOIN stocks AS s IB s.symbol = us.symbol;");

		while(rs.next() && rs.next())
			userID = rs.getString("userID");
			firstName = rs.getString("firstName");
			lastName = rs.getString("lastName");
			symbol = rs.getString("symbol");

			System.out.println(userID + "\t" +firstName+ "\t" +lastName+ "\t" +symbol);

	public static void main(String[] args) throws Exception
		Query q = new Query();

Is This A Good Question/Topic? 0
  • +

Replies To: database query result

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3212
  • View blog
  • Posts: 14,146
  • Joined: 20-September 08

Re: database query result

Posted 15 May 2013 - 02:01 AM

Make sure you've set up the DSN properly or use a DSN-les approach


 while(rs.next() && rs.next())
Why do you do that? It will advance the cursor twice each time in the loop
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1