Help coderanch get a
new server
by contributing to the fundraiser

sunil ingalagi

+ Follow
since Apr 23, 2008
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sunil ingalagi

Is it possible to add selection handler to node of CellTree, no matter its Leaf node or not? i am using treeviewmodel to construct tree.
12 years ago

Rob Prime wrote:True. Moving to Java in General.

As for the class, I haven't been able to find it. Where did you get that piece of code from?

actually i want to access database table in jTable. im not able to do this in netbeans by drag n drop so i downloaded some example code

im pasting that code here..

Java Swing, 2nd Edition
By Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole
ISBN: 0-596-00408-7
Publisher: O'Reilly
//Let's try to make one of these databases work with a JTable for ouptut.

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;

public class DatabaseTest extends JFrame {

JTextField hostField;

JTextField queryField;

QueryTableModel qtm;

public DatabaseTest() {
super("Database Test Frame");
setSize(350, 200);

qtm = new QueryTableModel();
JTable table = new JTable(qtm);
JScrollPane scrollpane = new JScrollPane(table);
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3, 2));
p1.add(new JLabel("Enter the Host URL: "));
p1.add(hostField = new JTextField());
p1.add(new JLabel("Enter your query: "));
p1.add(queryField = new JTextField());
p1.add(new JLabel("Click here to send: "));

JButton jb = new JButton("Search");
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
getContentPane().add(p1, BorderLayout.NORTH);
getContentPane().add(scrollpane, BorderLayout.CENTER);

public static void main(String args[]) {
DatabaseTest tt = new DatabaseTest();

//A basic implementation of the TableModel interface that fills out a Vector of
//String[] structures from a query's result set.

class QueryTableModel extends AbstractTableModel {
Vector cache; // will hold String[] objects . . .

int colCount;

String[] headers;

Connection db;

Statement statement;

String currentURL;

public QueryTableModel() {
cache = new Vector();
new gsl.sql.driv.Driver();

public String getColumnName(int i) {
return headers[i];

public int getColumnCount() {
return colCount;

public int getRowCount() {
return cache.size();

public Object getValueAt(int row, int col) {
return ((String[]) cache.elementAt(row))[col];

public void setHostURL(String url) {
if (url.equals(currentURL)) {
// same database, we can leave the current connection open
// Oops . . . new connection required
currentURL = url;

// All the real work happens here; in a real application,
// we'd probably perform the query in a separate thread.
public void setQuery(String q) {
cache = new Vector();
try {
// Execute the query and store the result set and its metadata
ResultSet rs = statement.executeQuery(q);
ResultSetMetaData meta = rs.getMetaData();
colCount = meta.getColumnCount();

// Now we must rebuild the headers array with the new column names
headers = new String[colCount];
for (int h = 1; h <= colCount; h++) {
headers[h - 1] = meta.getColumnName(h);

// and file the cache with the records from our query. This would
// not be
// practical if we were expecting a few million records in response
// to our
// query, but we aren't, so we can do this.
while ( {
String[] record = new String[colCount];
for (int i = 0; i < colCount; i++) {
record[i] = rs.getString(i + 1);
fireTableChanged(null); // notify everyone that we have a new table.
} catch (Exception e) {
cache = new Vector(); // blank it out and keep going.

public void initDB(String url) {
try {
db = DriverManager.getConnection(url);
statement = db.createStatement();
} catch (Exception e) {
System.out.println("Could not initialize the database.");

public void closeDB() {
try {
if (statement != null) {
if (db != null) {
} catch (Exception e) {
System.out.println("Could not close the current connection.");
13 years ago
please tell me what kind of package is gsl.sql.driv and a method in that gsl.sql.driv.Driver(); and do i neeed to download any jar file for it?

public QueryTableModel() {
cache = new Vector();
new gsl.sql.driv.Driver();

its showing error on 3rd line as package gsl.sql.driv does not exist
13 years ago

Maneesh Godbole wrote:Check out the API for JOptionPane class. It has numerous showXXXDialog methods which will help you setup a modal dialog easily.

Thanks maneesh
13 years ago

Rob Camick wrote:Don't use a " child frame". Instead use a "modal JDialog".

Thank you very much Rob
13 years ago
Please anyone tell me as how to disable parent frame or window when
child frame is active.

when i click on a jbutton on one frame, a new frame will open. while this new frame is open i want to disable the first frame. like disabling any mouse click on first window. and when i close new frame then i have to enable first frame. and both the frames have main method in them.

and if i have to do this in net beans then how to do it?

thanks in advance for any help....
13 years ago
i have set it for both progress.jar and jdbc.jar.....
Im trying to connect progress databse in netbeans. sometime It is giving me error as no suitable driver found. and sometime it gives me error as no data. the driver i mentioned as "com.progress.sql.jdbc.JdbcProgressDriver". please help me.........
two programs running on different JVMs both the programs have main functions. i have created two frames and i have made a call to second program in jButtonActionPerformed block as pgm2.main(null) on clicking this button the other frame opens but when i pass some arguments in place of null it is not working please help me im still java beginner
16 years ago
I want to pass two strings from one program to other..
when i calll the other program with null parameter as pgm2.main(null), its working fine, please somebody tell me how do i pass arguments to other program...

Thanks in advance
16 years ago
now i have another problem ......
16 years ago
I got it.......
i just made a call to main method of of second frame in actionperformed method........
16 years ago
I have two Frames-> FrameA and FrameB and i have a jButton in FrameA on clicking this button i want FrameB to open please help me how do i write ActionPerformed event for this button.. please send some codes if you have...
Thanks in advance.....
16 years ago
i have used oracle as the database i think there is no problem in my java program because earlier it worked fine i think there is some problem in connecting to database.program is compiling but it keeps on running n not giving output.may be some problem in port number earlier i used 1521 it worked but now its not working please help me..........
im trying to retrieve a row from oracle database but its giving me an error as Error java.sql.SQLException: Exhausted Resultset
when i select an item from jcombobox its giving me this error
the error is in the following block..........
please help me

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:MyDatas","scott","tiger");
String selected_id = (String)jComboBox1.getSelectedItem();
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT tran_type,msc_type,resp,resp_desc,r_desc FROM reason_code WHERE r_code = '+ selected_id'");;

catch(Exception e)
System.out.println("Error " + e);


THANKS in advance............