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
{//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Class.forName("sun.jdbc\
.odbc.JdbcOdbcDriver");} catch(java.lang.ClassNotFoundException e)
{System.err.print("ClassNotFoundException:
");System.err.println(e.getMessage());}try {con =
DriverManager.getConnection(url,"Admin", "duke1");stmt =
con.createStatement();stmt.executeUpdate(createString);stmt.close();\
con.close();} catch(SQLException ex)
{System.err.println("SQLException: " +
ex.getMessage());}}}Code
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"
+cnfex.toString()
);}catch ( SQLException sqlex ) {// process
SQLExceptions
heresqlex.printStackTrace();output.append( "Connection unsuccessful\n"
+sqlex.toString()
);}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 ); } }
);}}