Results 1 to 6 of 6
- 11-22-2008, 02:42 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 40
- Rep Power
- 0
Making an Applet use a MySQL Database
I made an applet using Java, but now I want it to read information from a MySQL Database. The applet itself is a bunch of drop down menu lists that the user would pick an item from the list and it displays information about the item chosen.
Does anyone know the coding to make an applet be able to connect to a MySQL database?
My code is currently something like:
Pretty much instead of my code having the part:Java Code:import java.awt.*; import java.applet.*; public class Labeling extends Applet { Label nameLabel, resultLabel; Choice nameChoice; TextField resultText; public void init() { nameLabel = new Label("Name of Box"); nameChoice = new Choice(); nameChoice.add(""); nameChoice.add("Choice One"); nameChoice.add("Choice Two"); resultLabel = new Label ("Choice Picked: "); resultText = new TextField(4); resultText.setEditable(false); display(); addIn(); } public boolean action(Event event, Object object) { if(event.target == nameChoice) { if (true) { putValue(); } return(true); } else { return(false); } } public void putValue() { int choices = 0; String name = nameChoice.getSelectedItem(); if(name.equals("Choice One")) choices = 1; else if(name.equals("Choice Two")) choices = 2; resultText.setText("" + choices); } public void display() { // Use a grid bag layout. GridBagLayout gbag = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); setLayout(gbag); // Define the grid bag. gbc.weighty = 1.0; // use a row weight of 1 gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.anchor = GridBagConstraints.NORTH; gbc.anchor = GridBagConstraints.EAST; gbc.gridwidth = GridBagConstraints.FIRST_LINE_START; gbag.setConstraints(nameLabel, gbc); gbc.gridwidth = 0; gbc.anchor = GridBagConstraints.WEST; gbag.setConstraints(nameChoice, gbc); gbc.anchor = GridBagConstraints.EAST; gbc.gridwidth = GridBagConstraints.FIRST_LINE_START; gbag.setConstraints(resultLabel, gbc); gbc.gridwidth = 0; gbc.anchor = GridBagConstraints.WEST; gbag.setConstraints(resultText, gbc); } public void addIn() { add(nameLabel); add(nameChoice); add(resultLabel); add(resultText); } }
I want the applet to get the value of choice somehow in the database without having the if else statements because its around 2,000 choices and coding it would take an insanely long time.Java Code:if(name.equals("Choice One")) choices = 1; else if(name.equals("Choice Two")) choices = 2;
- 11-23-2008, 04:05 PM #2
I write code to write the choice as formatted java source code, then open it in the editor. For what you are asking there are almost always Selection.getIndex() methods which return an int. That can be used to index an array or a Collection.
Writing SQL statments may be done directly in the applet code as however they are normally done.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 11-24-2008, 07:39 AM #3
- 11-24-2008, 08:41 AM #4
Member
- Join Date
- Nov 2008
- Posts
- 40
- Rep Power
- 0
Applets are simple for me to make and manipulate. The database should be in the same machine thats hosting the website the applet is in.
- 11-30-2008, 12:59 PM #5
Member
- Join Date
- Nov 2008
- Posts
- 1
- Rep Power
- 0
I am new to java
"hello World!"
- 11-30-2008, 04:28 PM #6
Similar Threads
-
How to access MySQL Database in Eclipse 3.2
By nijava in forum EclipseReplies: 2Last Post: 12-12-2008, 03:04 PM -
Displaying data from mysql database.
By Haresh gurav in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 07-09-2008, 02:54 AM -
database with mysql using the netbeans 6.0
By kwesiaryee in forum New To JavaReplies: 2Last Post: 05-02-2008, 04:27 AM -
MySQL Database and Java
By shaggymac in forum Advanced JavaReplies: 1Last Post: 05-01-2008, 09:01 PM -
connecting to mysql database
By javagal in forum NetBeansReplies: 2Last Post: 08-04-2007, 12:36 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks