using JCheckBox, JButton and JTextArea with JDBC

hello.

Im wondering do any of you have links to web pages that include tutorials and source code on using JCheckBox, JButton and JTextArea with JDBC.would any of you who have experience with using JCheckBox, JButton, JTextArea and JDBC together be able to give me a few tips on how to select certain data from a table using JCheckBox, JButton and display the data in a JTextArea? examples of such data could be CD/DVD/Game data - i want users of my video library system to be able to view CD/DVD/Game information by name, age category, type and year. Users should be able to click on a check box (e.g. view by name, age category, type or year) and press a button. What would happen then is that data would appear in the text area (which could be placed beneath the check box + button inside a frame).

Thanks for the help

[847 byte] By [james-mcfaddena] at [2007-11-27 11:31:42]
# 1

Nothing special about using Swing components and JDBC. Of course they don't have any special relation to each other, so your question is odd.

You need to have decent knowledge of both Swing and JDBC to do what you want, so I suggest you find out some tutorials and start reading through them.

-Kayaman-a at 2007-7-29 16:41:16 > top of Java-index,Java Essentials,Java Programming...
# 2

hello.

thanks for the reply. how can I modify the following code so that JCheckBox can be used instead of JComboBox? i want users of my video library system to be able to view CD/DVD/Game information by name, age category, type and year. Users should be able to click on a check box (e.g. view by name, age category, type or year) and press a button. What would happen then is that data from the Product table would appear in the text area.

import javax.swing.*;

import java.sql.*;

import java.awt.*;

import java.awt.event.*;

public class Exercise32_6 extends JApplet {

private JComboBox jcboTableName = new JComboBox();

private JTextArea jtaResult = new JTextArea();

private JButton jbtShowContents = new JButton("Show Contents");

private Statement stmt;

public void init() {

initializeDB();

jbtShowContents.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent e) {

jbtShowContents_actionPerformed(e);

}

});

JPanel jPanel1 = new JPanel();

jPanel1.add(new JLabel("Table Name"));

jPanel1.add(jcboTableName);

jPanel1.add(jbtShowContents);

this.getContentPane().add(jPanel1, BorderLayout.NORTH);

this.getContentPane().add(new JScrollPane(jtaResult), BorderLayout.CENTER);

}

private void initializeDB() {

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

System.out.println("Driver loaded");

Connection connection = DriverManager.getConnection("jdbc:odbc:VideoLibrary");

System.out.println("Database connected");

stmt = connection.createStatement();

DatabaseMetaData dbMetaData = connection.getMetaData();

ResultSet rsTables = dbMetaData.getTables(null, null, null, new String[] {"TABLE"});

System.out.print("User tables: ");

while (rsTables.next()) {

jcboTableName.addItem(rsTables.getString("TABLE_NAME"));

}

}

catch (Exception ex) {

ex.printStackTrace();

}

}

private void jbtShowContents_actionPerformed(ActionEvent e) {

String tableName = (String)jcboTableName.getSelectedItem();

try {

String queryString = "select * from " + tableName;

ResultSet resultSet = stmt.executeQuery(queryString);

ResultSetMetaData rsMetaData = resultSet.getMetaData();

for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {

jtaResult.append(rsMetaData.getColumnName(i) + "");

}

jtaResult.append("\n");

while (resultSet.next()) {

for (int i = 1; i <= rsMetaData.getColumnCount(); i++) {

jtaResult.append(resultSet.getObject(i) + "");

}

jtaResult.append("\n");

}

}

catch (SQLException ex) {

ex.printStackTrace();

}

}

public static void main(String[] args) {

Exercise32_6 applet = new Exercise32_6();

JFrame frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setTitle("Exercise32_6");

frame.getContentPane().add(applet, BorderLayout.CENTER);

applet.init();

applet.start();

frame.setSize(380, 180);

frame.setLocationRelativeTo(null);

frame.setVisible(true);

}

}

james-mcfaddena at 2007-7-29 16:41:16 > top of Java-index,Java Essentials,Java Programming...
# 3

Why not stick with your old thread?

http://forum.java.sun.com/thread.jspa?threadID=5198395

dwga at 2007-7-29 16:41:16 > top of Java-index,Java Essentials,Java Programming...
# 4

i'll stick to my old thread then

james-mcfaddena at 2007-7-29 16:41:16 > top of Java-index,Java Essentials,Java Programming...