This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Populating Combo Box using one of the fields in oracle

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i need to know how to populate my combo box.i am able to cemnnect to the oracle make the resultset
while(result.next())
{
I Need the code to put the result in the combo box-
comboAppName
}
 
Ranch Hand
Posts: 297
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you're getting the result set, all you have to do now is grab that particular field and then set the combo box appropriately. So you would use rs.getBoolean(1) if the first column in the oracle table is boolean. Is this what you're asking?
 
aarti sharma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
yes this is what i'm looking for but just tell me if the foll code is correct
String app[];
int i;
stat=con.createStatement();
result=stat.executeQuery("select distinct(Field1) from Table");
while(result.next())
{
app[i]=result.getString(1);
i++;
}
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
Just some minor points:
a) ensure you initialise variable i (if its declared inside a method)

String app[];
int i = 0;
stat=con.createStatement();
result=stat.executeQuery("select distinct(Field1) from Table");
while(result.next())
{
app[i]=result.getString(1);
i++;
}

Then all you need is:
JComboBox combo = new JComboBox(app);

Hope to have been of any help,
Ambrose
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must be even more green. I am trying to use the combo box in an applet while populating the combo box with data from a MS Access 2000 MDB file. I get the following errors:
java.security.AccessControlException: access denied (java.lang.RuntimePermission
accessClassInPackage.sun.jdbc.odbc)
at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:272)
at java.security.AccessController.checkPermission(AccessController.java:
399)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:150
1)
at sun.applet.AppletSecurity.checkPackageAccess(AppletSecurity.java:169)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:105)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:120)
at TestBudget.init(TestBudget.java:27)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java:484)
ANY IDEAS?
My code looks like:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.sql.*;
import java.text.*;
public class SelectBudget extends Applet implements ActionListener,FocusListener
{
public void init()
{
// Define variables used in program
String[] datab = new String[500];
int i = 0;
datab[0] = "Init";
Connection a_connection = null;
Statement a_statement = null;
ResultSet rs = null;
DateFormat myFormat = new SimpleDateFormat("MM/dd/yyyy");
// Find database driver
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e)
{
System.err.println("Cannot find database driver" + e);
System.exit(1);
}
// Attempt to make a connection to the database
try
{
a_connection = DriverManager.getConnection("jdbc dbc:TestNew","","");
}
catch (SQLException e)
{
System.err.println("Cannot connect to database" + e);
System.exit(1);
}
// Setup to create a SQL statement
try
{
a_statement = a_connection.createStatement();
}
catch (SQLException e)
{
System.err.println("Cannot create statement" + e);
System.exit(1);
}
// Building the SQL statement to read the EMPLOYEE Database and display the results
try
{
String qryString = "SELECT TranDate, TranDesc, TranAmount, TranType FROM Budget";
rs = a_statement.executeQuery(qryString);
while(rs.next())
{
Date tranDate = rs.getDate(1);
String tranDesc = rs.getString(2);
String tranAmt = rs.getString(3);
String tranType = rs.getString(4);
datab[i] = tranDesc + " " + tranAmt + " " + tranDate + " " + tranType;
i++;
}
}
catch (SQLException e)
{
System.err.println("Error in reading database" + e);
System.exit(1);
}
JComboBox combo = new JComboBox(datab);
add(combo);
combo.requestFocus();
combo.addActionListener(this);
invalidate();
validate();
}
public void actionPerformed(ActionEvent thisEvent)
{ }
public void focusGained(FocusEvent e)
{ }
//Must be coded to implement FocusListener
public void focusLost(FocusEvent e) { }
}
 
    Bookmark Topic Watch Topic
  • New Topic