Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Please Help - No data found

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

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 ); } }
);}}

Share: 

 

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
Admin/duke1

 
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.




Tagged: