freelanceprogrammers.org Forum Index » Java

Please Help - No data found


View user's profile Post To page top
c_beginner2001 Posted: Thu Feb 21, 2002 3:14 pm


Joined: 31 Jan 2002

Posts: 24
Please Help - No data found
Hi everyone, I`m having a problem in getting a
database application to work. I have two pieces of source
code (1. CreateCoffess 2.AddressBook by <br>Deitel &
Deitel), both compile but when I run them both the same
error occurs:<br><br>Connection unsuccessful
java.sql.SQLException: No data found<br><br>I have set up the databases
through the control panel&gt;ODBC Datasource and don`t
know whats wrong, I have also set up a table for the
databases. Can<br>anyone 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).<br><br>Source code 1:
CreateCoffess:<br><br>import java.sql.*;<br><br>// Create the Coffee
Table.<br>public class CreateCoffees {<br><br>public static void
main(String args[]) {<br><br>String url =
"jdbc:odbc:CafeJava";<br>Connection con;<br>String createString;<br>createString
=
"create table COFFEES " +<br>"(COF_NAME varchar(32), "
+<br>"SUP_ID int, " +<br>"PRICE float, " +<br>"SALES int, "
+<br>"TOTAL int)";<br>Statement stmt;<br><br>try
{<br>//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");<br>Class.forName("sun.jdbc
.odbc.JdbcOdbcDriver");<br>} catch(java.lang.ClassNotFoundException e)
{<br>System.err.print("ClassNotFoundException:
");<br>System.err.println(e.getMessage());<br>}<br>try {<br>con =
DriverManager.getConnection(url,"Admin", "duke1");<br><br>stmt =
con.createStatement();<br>stmt.executeUpdate(createString);<br><br>stmt.close();
<br>con.close();<br>} catch(SQLException ex)
{<br>System.err.println("SQLException: " +
ex.getMessage());<br>}<br>}<br>}<br><br>Code
2: AddressBook:<br><br>import java.sql.*;<br>import
java.awt.*;<br>import java.awt.event.*;<br>import
javax.swing.*;<br><br>public class AddressBook extends JFrame {<br>private
ControlPanel controls;<br>private ScrollingPanel
scrollArea;<br>private JTextArea output;<br>private String
url;<br>private Connection connect;<br>private JScrollPane
textpane;<br><br>public AddressBook()<br>{<br>super( "Address Book
Database Application" );<br><br>Container c =
getContentPane();<br><br>// Start screen layout<br>scrollArea = new
ScrollingPanel();<br>output = new JTextArea( 6, 30 );<br>c.setLayout( new
BorderLayout() );<br>c.add( new JScrollPane( scrollArea
),<br>BorderLayout.CENTER );<br>textpane = new JScrollPane( output
);<br>c.add( textpane, BorderLayout.SOUTH );<br><br>// Set up
database connection<br>try {<br>url =
"jdbc:odbc:AddressBook";<br><br>Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver"
);<br>connect =
DriverManager.getConnection( url );<br>output.append( "Connection
successful
" );<br>}<br>catch ( ClassNotFoundException cnfex )
{<br>// process ClassNotFoundExceptions
here<br>cnfex.printStackTrace();<br>output.append( "Connection unsuccessful
"
+<br>cnfex.toString()
);<br>}<br>catch ( SQLException sqlex ) {<br>// process
SQLExceptions
here<br>sqlex.printStackTrace();<br>output.append( "Connection unsuccessful
"
+<br>sqlex.toString()
);<br>}<br>catch ( Exception ex ) {<br>// process remaining
Exceptions here<br>ex.printStackTrace();<br>output.append(
ex.toString() );<br>}<br><br>// Complete screen
layout<br>controls =<br>new ControlPanel( connect, scrollArea,
output);<br>c.add( controls, BorderLayout.NORTH );<br><br>setSize(
500, 500 );<br>show();<br>}<br><br>public static void
main( String args[] )<br> {<br>AddressBook app = new
AddressBook();<br><br>app.addWindowListener(<br>new WindowAdapter() {<br>public
void windowClosing(
WindowEvent e )<br> {<br>System.exit( 0 );<br> }<br> }
);<br>}<br>}<br><br>Thanks everyone
Reply with quote
Send private message
View user's profile Post To page top
dnp7 Posted: Thu Feb 21, 2002 5:17 pm


Joined: 19 Feb 2002

Posts: 22
Please Help - No data found
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<br><br>Good Luck,<br>Dmitry
Reply with quote
Send private message
View user's profile Post To page top
c_beginner2001 Posted: Thu Feb 21, 2002 9:48 pm


Joined: 31 Jan 2002

Posts: 24
Please Help - No data found
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.
Reply with quote
Send private message
View user's profile Post To page top
dnp7 Posted: Fri Feb 22, 2002 3:43 pm


Joined: 19 Feb 2002

Posts: 22
Please Help - No data found
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?
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help