Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Please Help - No data found

  Asked By: Jody    Date: Sep 07    Category: Java    Views: 1045

I'm having a problem in getting a
database application to work. I have two pieces of source
code (1. CreateCoffess 2.AddressBook by Deitel &
Deitel), both compile but when I run them both the same
error occurs:Connection unsuccessful
java.sql.SQLException: No data foundI have set up the databases
through the control panel>ODBC Datasource and don't
know whats wrong, I have also set up a table for the
databases. Cananyone please exaplian whats going wrong
and how I can fix it? I have given both peices of
code below incase this helps but I'm not sure if the
problem is with the code (unlikely if the same error
happens for both applications).Source code 1:
CreateCoffess:import java.sql.*;// Create the Coffee
Table.public class CreateCoffees {public static void
main(String args[]) {String url =
"jdbc:odbc:CafeJava";Connection con;String createString;createString
"create table COFFEES " +"(COF_NAME varchar(32), "
+"SUP_ID int, " +"PRICE float, " +"SALES int, "
+"TOTAL int)";Statement stmt;try
.odbc.JdbcOdbcDriver");} catch(java.lang.ClassNotFoundException e)
");System.err.println(e.getMessage());}try {con =
DriverManager.getConnection(url,"Admin", "duke1");stmt =
con.close();} catch(SQLException ex)
{System.err.println("SQLException: " +
2: AddressBook:import java.sql.*;import
java.awt.*;import java.awt.event.*;import
javax.swing.*;public class AddressBook extends JFrame {private
ControlPanel controls;private ScrollingPanel
scrollArea;private JTextArea output;private String
url;private Connection connect;private JScrollPane
textpane;public AddressBook(){super( "Address Book
Database Application" );Container c =
getContentPane();// Start screen layoutscrollArea = new
ScrollingPanel();output = new JTextArea( 6, 30 );c.setLayout( new
BorderLayout() );c.add( new JScrollPane( scrollArea
),BorderLayout.CENTER );textpane = new JScrollPane( output
);c.add( textpane, BorderLayout.SOUTH );// Set up
database connectiontry {url =
"jdbc:odbc:AddressBook";Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver"
);connect =
DriverManager.getConnection( url );output.append( "Connection
successful\n" );}catch ( ClassNotFoundException cnfex )
{// process ClassNotFoundExceptions
herecnfex.printStackTrace();output.append( "Connection unsuccessful\n"
);}catch ( SQLException sqlex ) {// process
heresqlex.printStackTrace();output.append( "Connection unsuccessful\n"
);}catch ( Exception ex ) {// process remaining
Exceptions hereex.printStackTrace();output.append(
ex.toString() );}// Complete screen
layoutcontrols =new ControlPanel( connect, scrollArea,
output);c.add( controls, BorderLayout.NORTH );setSize(
500, 500 );show();}public static void
main( String args[] ) {AddressBook app = new
AddressBook();app.addWindowListener(new WindowAdapter() {public
void windowClosing(
WindowEvent e ) {System.exit( 0 ); } }



3 Answers Found

Answer #1    Answered By: Cambria Lopez     Answered On: Sep 07

Your line <br>con =
DriverManager.getConnection(url,"Admin", "duke1");<br>hasn't work.<br>Look at
ODBC source
ones more.<br>You must have CafeJava named
source<br>and login/passw to your database must be

Answer #2    Answered By: Ray Lawrence     Answered On: Sep 07

I have changed the connection  line to<br><br>con
= DriverManager.getConnection(url,"","");<br><br>so
that there is no username or password and set  the
system dsn to CafeJava but the same error happens.

Answer #3    Answered By: Felicia Hill     Answered On: Sep 07

You should use connection  line like this:<br>con =
DriverManager.getConnection(url,"scott","tiger");<br>User name and password must
be determined.<br><br>What database are you use?

Didn't find what you were looking for? Find more on Please Help - No data found Or get search suggestion and latest updates.