?
Solved

An applet retrieving data from an access db.

Posted on 2003-03-30
4
Medium Priority
?
257 Views
Last Modified: 2010-03-31
Hello,
I would very much appreciate receiving some help with my flags applet. Actually MyApplet is supposed to read data from an access db which is composed of 2 cols: country(the name of the country) and icon(an animated gif representing the flag of the country).
The applet itself is composed of a combo box supposed to be filled with the countries'names from the db; when I make a choice and click the button, the flag should be displayed.
The problem I'm confronting here is that I can't fill the combo box from the db, however I've tested the connection and it's working. I believe that the problem is with the code of the combo. Anyway, Im sending along a copy of my code.
Thanks in advance for your help.

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.applet.*;
import java.net.URL.*;
import sun.jdbc.odbc.* ;

/*
<applet code="MyApplet" width="400" Height="300">
<param name="img" value="Austria.gif">
</applet>
*/
public class MyApplet extends Applet
     implements ActionListener, ItemListener {

// Componenets of the applet
Choice combo;
Button but1;
Image img;

public void init() {
// Here comes the initialization of the layout, combo, button, starting
// image and the connection

setLayout (new FlowLayout (FlowLayout.CENTER,50,150));
img = getImage(getDocumentBase(),getParameter("img"));
but1 = new Button ("Click");
add (but1);
but1.addActionListener(this);
combo = new Choice();
new sun.jdbc.odbc.JdbcOdbcDriver();
String url="jdbc:odbc:dsn1";
String country;

try {
          Connection con = DriverManager.getConnection(url);
          Statement stmt = con.createStatement();
          ResultSet rs = stmt.executeQuery ("SELECT country FROM country");

          while (rs.next()) {
          country=rs.getString("country");
          combo.addItem(country);
          rs++;
          }
     stmt.close();
} catch (SQLException e) {
  System.out.println("Cannot create SQL statement");
}
add (combo);
combo.addItemListener(this);
}

public void itemStateChanged (ItemEvent ie) {
repaint();
}

public void actionPerformed (ActionEvent ae) {
if (ae.getSource()==Click){
Connection con = DriverManager.getConnection(url);
String selection=combo.getSelectedItem;
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT ICON FROM COUNTRY WHERE COUNTRY="+selection);
img=getImage(rs);
repaint();
}

public void paint (Graphics g) {
g.drawImage(img,150,40,this);
     }
}

0
Comment
Question by:dtaifour
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 80 total points
ID: 8235435
I reckon it's throwing a SecurityException, as you shouldn't be able to look up DSNs from an Applet...

I think with an Access database, you'll either have to write a servlet to sit next to it, and have:

  Applet <-> Servlet <-> Access

Or, use RMI, to do the same...

I would recommend in this case that you use Postgresql, or MySQL instead of access, as they can be accessed via the internet and JDBC type 4 drivers :-)

Both Databases are free:

Postgresql:
http://www.postgresql.org

Postgresql JDBC driver:
http://www.postgresql.org

MySQL:
http://www.mysql.com/

MySQL Driver:
http://www.mysql.com/downloads/api-jdbc-stable.html
0
 

Expert Comment

by:CleanupPing
ID: 9058384
dtaifour:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9735699
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept TimYates' comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question