Cannot Show SQL Data In JTable?

Feb 27, 2014

I'm trying to display the data from database in a jtable by following the jtable demo example in Java Tutorials Sample Code; but, I couldn't output the data to the jtable. The following code is what I've done so far.
 
import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;
public class Patient { static String szJdbcURL = "jdbc:oracle:thin:@129.78.110.188:1521:MyDB";                
static String szUser = "...";                
static String szPasswd = "...";                
static String szModelName = "...";

[Code] .....

View Replies


ADVERTISEMENT

JTable Elements Only Show Up When Clicked On Or JFrame Resized

Jan 18, 2015

This is an old project that I had working probably 2 years ago. Since I reopened it the only thing I have changed is the database location. This is a very basic project I did to dip my toes in to Java. I'm going to add it to my portfolio but just to clarify I am not a Java developer so this is mainly there to show that I am not completely blind when it comes to Java.

//Import libraries
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Connection;
import java.sql.DriverManager;

[Code]...

Errors when I click the button that launches the JFrame:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 6 >= 6
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.getValueAt(Unknown Source)
at javax.swing.JTable.getValueAt(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)

[Code]...

It will launch the window but it will be blank. If I resize the window it will show me the headers. If I click below the headers were the data should be, it will show me the data.

Since it has been so long the only thing I can think of is some of the code has become antiquated. As I said, this was working originally. I just fired it up again to take some screenshots for my portfolio.

View Replies View Related

Use JTable To Show Contents From MySQL Directly Without Mouse Clicking

Jan 31, 2014

i want to make adding into mysql database and then when i click adds, jtable show those data automatically. but it seem to get error at display part, it shows " Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - illegal start of expression" and jtable do not show the added data but in mysql, data is properly kept.

private void jtPropertyChange(java.beans.PropertyChangeEvent evt) {
DefaultTableModel model = (DefaultTableModel) jt.getModel();
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
String sql = "SELECT * FROM `companya`";

[Code].....

the adding part seems to be fine

View Replies View Related

Swing/AWT/SWT :: How To Select Items Of JList2 From MYSQL To Show In Jtable

Jan 31, 2015

There is a Jlist(Jlist1) which is populated with the columnNames from MYSQL. Then There is another empty Jlist (Jlist2) which the user can add items from Jlist1. At this stage I want to know how I can select items of JList2 from MYSQL to show in Jtable. Because the columnnames(items) of Jlist2 is less than the Jlist1. Like Spss that when you select variables from available list then you can add some of variable to selected list and do analysis.

View Replies View Related

Runnable Jar Does Not Show Data From Database

Mar 13, 2014

I am still working on my java course and now we have to create a jar file from a previous project (this is a project where a connection to the database is made and data is shown in a frame).

When I follow the instruction in my course material I don't get it to work. I've tried the following:

1. Open eclipse on windows xp
2. Right click on the project folder in eclipse
3. Click on "export" in the menu that appears
4. Choose "runnable jar"
5. click next
6. I insert the following parameters:

- Launch configuration --> I select my main class
- export destination --> I select the folder D:
- library handling --> Package required libraries into generated jar

7. click Finish

This is what happens when I dbl click the jarfile (wampserver is running):

1. I get an error: "SQL ERROR: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server."

2. I click ok on the message and the following message appears: "SQL Error: null"

3. I click ok on this message and the frame with the fields appears without data from the database.

This is a crosspost to: [URL] ...

View Replies View Related

Swing/AWT/SWT :: How To Show Data From Database In JXTreeTable

Aug 11, 2014

How I can show data from Database in JXTreeTable?

View Replies View Related

Getting Text File Data To Show In Code

Jun 17, 2014

Here is my code so far,i have created a "birthdays.text" file with various peoples birthdays. How do I implement that into my code?

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class BirthdayBinarySearchTree {
private BSTnode root;

[code]....

View Replies View Related

JSP :: How To Show Data In Text Box When Click On Edit Button

Mar 22, 2014

i want to know how to data show in text box according click edit button.this is jsp file.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.sql.*,java.util.*"%>
<%!ResultSet rs = null;%>

[code]....

View Replies View Related

JSF :: Dialog Box Data Show In Primefaces Datatable When Click On CommandButton

Aug 5, 2014

When i click on 'Add Invoice' button open a dialog box. input data in dialog box. After click on 'Save Invoice' all the data of dialog box is render in primfaces datatable. After that click on 'Save Invoices' all data of primefaces datatable and HTML table data are store in ipsDetail and Invoice object of Managed Bean class.

XHTML file :

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">

[Code] .....

Here, Problem is ipsDetail elements NULL when click on 'Save Invoice' button in addRow() so that primefaces datatable not updated. So that i can not insert new invoice data in database table.

View Replies View Related

Swing/AWT/SWT :: How To Get Data From JTextField Over To JTable

Jun 20, 2014

I am trying to get the data entered in a JTextField into a JTable but not clear on how. The LeftPanel is where the button is located and the RightPanel is where the JTable is. I want the actionPerformed to update the row of the JTable but I can't figure out how. There is another class that controls the GUI but did not think it was necessary to include. Also, I am aware that I am getting an error at the addRow line, can't seem to alleviate it.

public class LeftPanel extends JPanel {

private static final long serialVersionUID = -2311952438693382407L;
private RightPanel rPanel;
public LeftPanel(){
Dimension size = getPreferredSize();
size.width = 250;
setPreferredSize(size);

[code]....

View Replies View Related

Swing/AWT/SWT :: Refreshing Data In A JTable?

Apr 24, 2014

I have been trying to learn a bit about JTables for a project I want to undertake. I have created a new JFrame in netbeans and added a button. Onclicking the button I want add some data to a JTable model and then output the JTable with the data. When I click the button again I want the same process to happen again and overwrite the previous table being displayed.

I have written the following code below:

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

[code].....

The problem I have is that when I click the button for a second time the table stays on the screen exactly as it did following the first click. I can see that the data in the model is changing so I am not sure why a new JTable is not drawn.

View Replies View Related

Capturing User Data Through JTable

Jan 1, 2015

I am developing a quotation generator application using Java. I am using a JTable to capture user input(this input is taken from a database i.e. each cell of the tale will have a combobox where the user can select an input value). when the user is done he/she has to print the quotation as A4 page.

My issue is: Is there a way of doing it besides using the JTable?

View Replies View Related

Swing/AWT/SWT :: Saving And Loading Data Of Jtable

Apr 6, 2015

I am trying to make a program where a user can enter guests name for a hotel, the JTable includes rows for the name of the tenant, the room number, month etc.

I've made the table, however I am having some trouble in saving the data that I put into the table. I used jtextfield and a jbutton to but data into the jtable. I am trying to save the data, and load it just buy clicking a button.

table.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"Room", "Name", "Month", "Payment"//table rows
}
));

This is my basic table. And what I'm trying to do to save the data is:

DefaultTableModel model = new DefaultTableModel();
private JFileChooser myJFileChooser = new JFileChooser(new File("."));
private void saveTable() {
if (myJFileChooser.showSaveDialog(null) ==
JFileChooser.APPROVE_OPTION ) {
saveTable(myJFileChooser.getSelectedFile());

[Code] ....

When I run my program, I'm able to click on a button, and the dialog box will appear, I'm also able to save the data to a file. However when I click on the retieve data button I made the dialog box opens, the file is there, however when I click it, nothing happens.

View Replies View Related

Swing/AWT/SWT :: JTable - How To Repaint With Updated Data

Jun 5, 2014

Here's what I would like to happen:

Java/Swing dialog box appears on the user's screenIt allows the user to enter 2 values into labelled text fields (fname/sname)They select a "Click Me" push button which I hope will write the data into the table. But the table does not get refreshed.

If I minimise the dialog box and then open it again, the data still does not appear.

The code I originally built using eclipse/WindowBuilder. I've cut it back and tried to isolate the issue. But I still cannot figure it out.

I've added some diagnostic log messages to ensure that I am seeing the various events I think I need to see and have put code in the action callbacks etc.

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;

[Code] .....

View Replies View Related

Filtering MySQL Data To JTable In Particular Column

Jun 11, 2014

I have a jtable. the fields are like Product_code,Product_name,Qty,Rate in my java program.. now i want to do is when i press a first letter in my jtable under Product_name like "P" it will display the reminding Product_name which will have the starting letter of "P" like pen, pencil, peper like this i want to populate in my jtable.

View Replies View Related

Int On JTable - Display Primitive Data Types

Jun 5, 2014

I have an int array that has information read from a file. Now i want to display this int on a jtable but ofcourse i cant display primitive data types.. and also you cannot cast an int[] to an Object[], so I am stuck...

View Replies View Related

Swing/AWT/SWT :: How To Display Hugeclob Data On JTable

Feb 26, 2015

I was trying to run an sql query to display onto my jtable. However, i got this as a result:

oracle.sql.CLOB@11876a2

When I run the same SQL query on Toad i get the field hugeclob and one is then able to see whats inside the field. I want to basically either have a hugeclob on my jtable or perhaps to display on a textarea the data

View Replies View Related

Saving Edited Data From JTable Into Database?

Jul 16, 2014

The Table Model

package presentation;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import business.*;
public class BgTableModel extends AbstractTableModel

[code]....

View Replies View Related

Saving Edited Data From JTable Into Database

Jul 16, 2014

I've tried everything but in vain..I want to save the data from the table into the database, I can easily connect to the database. All I want is how to get the values from the table. I've tried this method to get the values but its not working because of the contructor error in the BgTableModel class.

Tried Method
public void writeBgEdu() {
int last=gtm.getRowCount();
System.out.println(last);
for( int i=0;i<last;i++) {
if(((String) gtm.getValueAt(i,0))!=null)

[Code] .....

View Replies View Related

Edit Data Of JTable Using Default Double Editors

Feb 5, 2015

As shown in the SS I show the data of the batch from the db.Now I want to edit the data of the jtable using the default Double editors and also show the data using a Date renderer in dd/MM/yyyy format.The problem is when the data is loaded from the db,I am not knowing how to implement and set the editors to double and date.I am new in java.The code of the above is shown as follows.

Java Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Billing;
import java.awt.Component;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

[Code]...

View Replies View Related

Focus Listener - JTable Stops Showing Data In It

Apr 5, 2014

public void createSearchArea(){
filterText = new JTextField("Search Here");
filterText.setForeground(Color.gray);
filterText.setBounds(130,5,950,25);
filterText.getDocument().addDocumentListener(
new DocumentListener() {

[Code] .....

I want to add a text to JTextField whenever the text field is clicked it should be removed and if user types nothing then it should come back.

I've used focus listener but on focus lost my JTable also stops showing data in it.

View Replies View Related

Swing/AWT/SWT :: Copy Selected Data From JTable Cell To Clipboard

Feb 18, 2014

I have a jtable that I would like to copy from a cell that I select to clipboard. How could I do these.

View Replies View Related

Swing/AWT/SWT :: Sort JTable Data On Year Between A Range Of Years?

Jan 16, 2014

i have a JTable with data that contains a column with Years.

I want to get the user to be able to sort the data between a range of two years.

Example:

a user sets te filter so he/she can view all the data between the years 1990 and 2000.

I am a beginner in Java and don't know how to code such a filter.

I guess it will be something with an if/Else statement or a loop?

View Replies View Related

Save JTable Contents So Table Data Remains After Program Restart?

May 22, 2014

how I would achieve the concept of saving the contents of a JTable, so even after program restarts, the table would retain the data. I am developing a utility that will be a password storage book. The user enters passwords and they are stored in a JTable. Currently, the table resets whenever the program is restarted, however I would like it to keep it's data. URL....

View Replies View Related

New Lines Don't Show Up In File But They Do Show Up On Console

Apr 30, 2015

I have the following code.

class A {
List<StringBuilder> list;
public void output(List<StringBuilder> objectToOutput){
try(BufferedWriter bw = new BufferedWriter(new FileWriter("temp.txt"))){
for(StringBuilder row:objectToOutput) bw.write(row.toString());
}catch(IOException e){}

[code]....

Why don't the a's show up on the console? I put them in as part of the debugging process and now I don't understand why they don't show up in both places.

View Replies View Related

Make Date Column Show Only Date And TimeIn And TimeOut Column Only Show Time

Mar 11, 2014

How do i make the 'date' column show only the date and 'timeIn' and 'timeOut' column only show the time. In my database table my 'date' column is a date type and 'timeIn' and 'timeOut' column is time.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved