craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > General QuickTable Support/Help Post New Topic   Post A Reply
Refresh does not show any records printer friendly version
next newest post | next oldest post
Author Messages
Rene
Private

Gender: Male
Location: Venhorst The Netherlands
Registered: Apr 2007
Status: Offline
Posts: 5

Click here to see the profile for Rene Send email to Rene Send private message to Rene Find more posts by Rene Edit or delete this message Reply w/Quote
Posted Wednesday, April 18, 2007 @ 07:50:51  

Hello,

This is my first program in Java so please be gentle as I probably do something simple wrong.

General info:
I want to create a simple application where a user can print multiple printable files with defined printersettings (duplex, mediatype etc)

So I want to:
1- Read a directory structure.
2- Write it to a database.
3- Show it to the user.
4- Select all the rows wich can be printed (depending on what printer is selected).

I`m Using NetBeans IDE 5.5

1 and 2 were no problem but when it comes to point 3 I get lost.

When I load a query in the "initComponents()" method the table data is shown but when I try to set a new query the table gets blank. There were records added in the table.

I like to use a method to build the table to which I pass a SQL string. ("tabledefinition(sSQL)")
when the refresh is called a Demo message pops up so it has been triggered the next lines were also processed.

Here is my code.

package my.batchprint;

import java.lang.Class;
import java.net.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.JTable;

import quick.dbtable.DBTable;
import quick.dbtable.DatabaseChangeListener;
import quick.dbtable.DBTableCellListener;
import quick.dbtable.CellPropertiesModel;
import quick.dbtable.DBTableErrorListener;
import quick.dbtable.Column;
import quick.dbtable.DataMap;
import quick.dbtable.CellComponent;
import quick.dbtable.PrintProperties;
import quick.dbtable.Filter;
import quick.dbtable.Skin;

public class BatchPrintUI extends javax.swing.JFrame
{
File jarFile = new File(BatchPrintUI.class.getProtectionDomain().getCodeSource().getLocation().toURI());

public String HomePath = jarFile.getParent();
public static Connection GeneralDBConnect;
public static Statement stmt;
public static String sSQL;
public static int iData_job_id = new Integer(-1);
public static String sUser;
public static Vector columnNames;
public static Vector data;


/** Creates new form BatchPrintUI */
public BatchPrintUI() throws Exception
{
connection();
sUser = System.getProperty("user.name");
try
{
stmt = GeneralDBConnect.createStatement();
stmt.execute("insert into data_job (creator,username,jobstatus) values (\'" + sUser + "\',\'" + sUser + "\',1)");
stmt.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
try
{
stmt = GeneralDBConnect.createStatement();
ResultSet rs = stmt.executeQuery("select max(data_job_id) as max_data_job_id from data_job where username = \'" + sUser + "\'");
Integer MaxValue = new Integer(-1);
if(rs.next())
{
MaxValue = rs.getInt(1);
}
iData_job_id = MaxValue.intValue();
rs.close();
stmt.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
initComponents();
sSQL = "select sequence, icon, name from data where jobid = 61";// + iData_job_id;
tabledefinition(sSQL);

}

public void connection () throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException
{
DriverManager.registerDriver(
(Driver) Class.forName( "com.sybase.jdbc2.jdbc.SybDriver" ).newInstance() );

GeneralDBConnect = DriverManager.getConnection("jdbc:sybase:Tds:195.75.197.210:49152?ServiceName=BatchPrint&CHARSET=utf8","dba","sql" );
}

public void tabledefinition(String sSQL)
{
dBTable_Data.clearAllSettings();
DBTable dBTable_Data = new DBTable();
try
{
dBTable_Data.setConnection(GeneralDBConnect);
dBTable_Data.connectDatabase("com.sybase.jdbc2.jdbc.SybDriver","jdbc:sybase:Tds:195.75.197.210:49152?ServiceName=BatchPrint&CHARSET=utf8","dba","sql");//GeneralDBConnect);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
dBTable_Data.debug = true;
dBTable_Data.setSelectSql(sSQL);
try
{
dBTable_Data.refresh();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
SimpleSkin mySkin = new SimpleSkin();
dBTable_Data.setSkin(mySkin);

Column Col = dBTable_Data.getColumn(0);
Col.setType(Types.NUMERIC);
Col.setReadOnly(false);
Col.setHeaderValue("Seq");
Col.setPreferredWidth(25);

Col = dBTable_Data.getColumn(1);
Col.setReadOnly(true);
Col.setHeaderValue("");
Col.setPreferredWidth(20);
Hashtable imageHash = new Hashtable();
imageHash.put("1",new ImageIcon(HomePath + "/images/folder_closed.png"));
imageHash.put("2",new ImageIcon(HomePath + "/images/folder_opened.png"));
imageHash.put("3",new ImageIcon(HomePath + "/images/document_supported.png"));
imageHash.put("4",new ImageIcon(HomePath + "/images/document_unsupported.png"));
dBTable_Data.setCellComponent(Col,Column.IMAGE_CELL,imageHash);

Col = dBTable_Data.getColumn(2);
Col.setReadOnly(true);
Col.setHeaderValue("Name");
Col.setPreferredWidth(265);
}

public class SimpleSkin extends Skin
{
Font headerFont = new Font("SansSerif", Font.BOLD, 9);
Font font = new Font("SansSerif", Font.PLAIN, 9);

public SimpleSkin()
{
put(Skin.HEADER_FONT,headerFont);
put(Skin.TABLE_FONT,font);
put(Skin.ROW_HEIGTH, new Integer(14));
}
}

File currentDir;
String[] safiles;
String sIcon;
public String sDir;
File fDir;

public void listDirectory(String sDir)
{
fDir = new File(sDir);
String sCurPath = fDir.getAbsolutePath()+File.separator ;

safiles = fDir.list();

String sFileName = new String();
String sPathName = new String();

if(safiles == null)
{
jTextField_Folder.setBackground(Color.red);
jTextField_Folder.requestFocus();
jTextField_Folder.selectAll();
}
else
{
jTextField_Folder.setBackground(Color.white);
for(int i=0; i< safiles.length; i++)
{
File curFile = new File(sCurPath + safiles[i]);
if(curFile.isDirectory())
{
sIcon = "1";
}
else
{
sIcon = "3";
}

String sValue = "\'" + sUser + "\'," + iData_job_id + "," + (i + 1) + ",\'" + safiles[i] + "\',\'" + sCurPath + safiles[i] + "\'," + sIcon;
try
{
stmt = GeneralDBConnect.createStatement();
stmt.execute("insert into data (creator, jobid, sequence, name, path, icon) values (" + sValue + ")");
stmt.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
}
sSQL = "select sequence, icon, name from data where jobid = " + iData_job_id;
tabledefinition(sSQL);
}
}
public void actionPerformed(ActionEvent e) {
}

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
dBTable_Data = new quick.dbtable.DBTable();

//create a new quicktable
DBTable dBTable_Data = new DBTable();
dBTable_Data.setConnection(GeneralDBConnect);//connectDatabase("com.sybase.jdbc2.jdbc.SybDriver","jdbc:sybase:Tds:195.75.197.210:49152?ServiceName=BatchPrint&CHARSET=utf8","dba","sql");

}// </editor-fold>

private void focuslost(java.awt.event.FocusEvent evt) {
String sValue = jTextField_Folder.getText();
listDirectory(sValue);
}

private void jButton_ExitActionPerformed(java.awt.event.ActionEvent evt) {
try
{
stmt.close();
GeneralDBConnect.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
System.exit(0);
}

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new BatchPrintUI().setVisible(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}

// Variables declaration - do not modify
private quick.dbtable.DBTable dBTable_Data;
}

Code:
[/CODE] [CODE]

Rene
Private

Gender: Male
Location: Venhorst The Netherlands
Registered: Apr 2007
Status: Offline
Posts: 5

Click here to see the profile for Rene Send email to Rene Send private message to Rene Find more posts by Rene Edit or delete this message Reply w/Quote
Posted Wednesday, April 18, 2007 @ 12:35:17  

This info was in the debug window

compile:
Executing row count sql=SELECT COUNT(*) from data where jobid = 61
Time taken to execute rowcount sql=441ms
Time taken to execute select sql=70ms
Database meta data information received from jdbc driver
Column 1: Name: sequence
ReadOnly: true
Data Type: INTEGER
Precision: 0
Scale: 0
Signed: true

Column 2: Name: icon
ReadOnly: true
Data Type: INTEGER
Precision: 0
Scale: 0
Signed: true

Column 3: Name: name
ReadOnly: true
Data Type: LONGVARCHAR
Length: 2147483647

Executing row count sql=SELECT COUNT(*) from data where jobid = 84
Time taken to execute rowcount sql=30ms
Time taken to execute select sql=40ms
Database meta data information received from jdbc driver
Column 1: Name: sequence
ReadOnly: true
Data Type: INTEGER
Precision: 0
Scale: 0
Signed: true

Column 2: Name: icon
ReadOnly: true
Data Type: INTEGER
Precision: 0
Scale: 0
Signed: true

Column 3: Name: name
ReadOnly: true
Data Type: LONGVARCHAR
Length: 2147483647

debug:
BUILD SUCCESSFUL (total time: 39 seconds)

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Monday, April 23, 2007 @ 04:46:02  

You have defined dBTable_Data as a local variable (DBTable dBTable_Data = new DBTable();
) within the method tabledefinition. So every time you are creating new DBtable and you are not adding that to your frame. Please read CustomerOrderDemo sample , it will give you more insights.

I would change the folowing method as below.

Code:

public void tabledefinition(String sSQL, boolean isFirstTime)
{

if( isFirstTime)
{
dBTable_Data = new DBTable();
dBTable_Data.debug = true;

try
{
dBTable_Data.setConnection(GeneralDBConnect);
}
catch (SQLException ex)
{
ex.printStackTrace();
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
}

if( !isFirstTime)
dBTable_Data.clearAllSettings();


dBTable_Data.setSelectSql(sSQL);

try
{
dBTable_Data.refresh();
}
catch (SQLException ex)
{
ex.printStackTrace();
}

if( isFirstTime)
{
SimpleSkin mySkin = new SimpleSkin();
dBTable_Data.setSkin(mySkin);

Column Col = dBTable_Data.getColumn(0);
Col.setType(Types.NUMERIC);
Col.setReadOnly(false);
Col.setHeaderValue("Seq");
Col.setPreferredWidth(25);

Col = dBTable_Data.getColumn(1);
Col.setReadOnly(true);
Col.setHeaderValue("");
Col.setPreferredWidth(20);
Hashtable imageHash = new Hashtable();
imageHash.put("1",new ImageIcon(HomePath + "/images/folder_closed.png"));
imageHash.put("2",new ImageIcon(HomePath + "/images/folder_opened.png"));
imageHash.put("3",new ImageIcon(HomePath + "/images/document_supported.png"));
imageHash.put("4",new ImageIcon(HomePath + "/images/document_unsupported.png"));
dBTable_Data.setCellComponent(Col,Column.IMAGE_CELL,imageHash);

Col = dBTable_Data.getColumn(2);
Col.setReadOnly(true);
Col.setHeaderValue("Name");
Col.setPreferredWidth(265);

//this will make sure to use the column properties for next sql
dBTable_Data.useOldColumnProperties(true);
}

}

Rene
Private

Gender: Male
Location: Venhorst The Netherlands
Registered: Apr 2007
Status: Offline
Posts: 5

Click here to see the profile for Rene Send email to Rene Send private message to Rene Find more posts by Rene Edit or delete this message Reply w/Quote
Posted Tuesday, April 24, 2007 @ 05:08:48  

Thanks for the tip I got it to work perfectly

The Private statement was in uneditable code but I found how to alter it (property in Designmode)

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios