Kadjo

SoftDev Journal

About This Journal

24 June 2007 by Jojo Makiling

Technical concerns tend to find a solution as long as there are good people working on them. And Linux has the very best. - Linus Torvalds

Moving the Cursor in a Scrollable Result Set

May 28th, 2006 by pepesmith

This example demonstrates the various methods for moving the cursor in a scrollable result set.

try {
        // Create a scrollable result set
        Statement stmt = connection.createStatement(
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table");
   
        // Move cursor forward
        while (resultSet.next()) {
            // Get data at cursor
            String s = resultSet.getString(1);
        }
   
        // Move cursor backward
        while (resultSet.previous()) {
            // Get data at cursor
            String s = resultSet.getString(1);
        }
   
        // Move cursor to the first row
        resultSet.first();
   
        // Move cursor to the last row
        resultSet.last();
   
        // Move cursor to the end, after the last row
        resultSet.afterLast();
   
        // Move cursor to the beginning, before the first row.
        // cursor position is 0.
        resultSet.beforeFirst();
   
        // Move cursor to the second row
        resultSet.absolute(2);
   
        // Move cursor to the last row
        resultSet.absolute(-1);
   
        // Move cursor to the second last row
        resultSet.absolute(-2);
   
        // Move cursor down 5 rows from the current row.  If this moves
        // cursor beyond the last row, cursor is put after the last row
        resultSet.relative(5);
   
        // Move cursor up 3 rows from the current row.  If this moves
        // cursor beyond the first row, cursor is put before the first row
        resultSet.relative(-3);
    } catch (SQLException e) {
    }

Posted in Java | No Comments »

Overcoming RowFilter and Select Limitation

May 26th, 2006 by pepesmith

In ADO.NET, you can use the DataView.RowFilter property and the DataTable.Select method to filter a subset of records. However, the expressions that you can use have limitations. This article demonstrates three techniques to work around the limitations of the filter expressions.

'DataTable1 is an existing DataTable object.
DataTable1.Columns.Add("Flag", GetType(Boolean))
DataTable1.Columns("Flag").ColumnMapping = MappingType.Hidden
Dim dr As DataRow
For Each dr In DataTable1.Rows
  ' If the criteria are satisfied Then
      dr("Flag") = True
  ' End If
Next
Dim dv As New DataView(DataTable1, "Flag = True", "", DataViewRowState.CurrentRows)
DataGrid1.DataSource = dv

Posted in .NET General Topic, Miscellaneous | No Comments »

Maybe a help..

May 24th, 2006 by pepesmith

I'm trying to use sqlite in my java progs..might be a help...
posted in java forum

HI. The problem is the package in the site. When you use the fck.mthr class SQLite.JDBCDriver, from this package, it does not point to the classes in the JDBC2x, but to a crazy "JDBC2y".

Try the package that I foud out at :

http://dev.radrails.org/trac/browser/trunk/org.sqlite.driver/SQLite?rev=373.

It worked with at the first time.

You will have to organize the files, close to the package from http://www.ch-werner.de/javasqlite/overview-summary.html

OBS : I also got it with the package from "http://www.ch-werner.de/javasqlite/overview-summary.html" , but with a diferent code that I don´t think that is secure. I jumped the class JDBCDriver, and I use the classes in JDBC2x :

import java.sql.*;
import SQLite.JDBC2x.*;

public class SQLiteJDBC
{
public static void main( String args[] ) throws SQLException
{
String url2 = "jdbc:sqlite:/C:\\teste.db";
try {

JDBCConnection c = new JDBCConnection (url2,"");

JDBCStatement st =(JDBCStatement) c.createStatement();

String campo;
int i = 0;
ResultSet rs = st.executeQuery( "SELECT * FROM teste;" );
while ( rs.next() ) {
campo = rs.getString("teste");
System.out.println( "Linha " + i + " -> campo \"teste\" = " + campo );
i++;
}
rs.close();
st.close();

c.commit();
c.close();
} catch ( SQLException e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(1);
}
}
}

//-------------------------------------------------------------------------

*********************ATENTION***************************

Please, if you tested it and it worked to you, please, repass to the other forums. It was dificult to find this answer on web.

See you..........

Posted in Java | No Comments »

How to Print in JetBee

May 24th, 2006 by pepesmith

How to print a report.

There are several approaches to code a report printing applications using the JetBee print library. It will depend on whether you want to use the Java print model, or an alternative print model provided by the JetBee print library. And it also depends on if you want to print under the foreground or a background thread.

If you have existing Java programs and want them to utilize the library, then a quick and easy way is to use the Java print mode. See How to print using the Java print model.

If you want to use the JetBee print model, please see How to print using the JetBee print model.

How to print using the Java print model.

The JetWriter class can also work with the Java Printable class easily. If you have existing programs that are using the Java Printable class, or if you want to continue to use the Java Printable class while taking advantages of the JetBee print library, you can do this:

class MyReport implements Printable {
...
}
JetWriter jw = new JetWriter();
boolean go = jw.jetPrintDialog();
if (go) {
jw.jetExePrintable(new MyReport()); // execute in foreground thread.
}

If you want to use a background thread to print the report, you need simply to use the jetRunPrintable() instead:

...
if (go) {
jw.jetRunPrintable(new MyReport()); // execute in a background thread.
}

How to print using the JetBee print model.
This can be easily achieved by using a JetWriter object:

JetWriter jw = new JetWriter();

Once you have a JetWriter object, you can print using the member functions of the writer. Or you may obtain a Graphics2D object with which all the powerful Graphics2D functions can be used to print the report. For example:

// optionally set the print job attributes here.
jw.jetOpenReport();
Graphics2D g = jw.jetGetGraphics2D();
g.drawString("JetBee Sample 1 Report", 220, 150);
g.drawLine(220, 152, 355, 152);

This method is a convenient way to code for reports that are relatively simplier and can be finished quickly. There is no need to code for other class or routines. However, program coded in this way will run in the foreground thread.

If it is needed to print a report in a background thread, or using the features provided by the JetReport or its derived classes, then you may consider to create a class to contain the codes that print the report.

Your class would be derived from the JetReport or one of its derived classes such as the JetGraphics2DReport class.

For example:

class ProductList extends JetGraphics2DReport {
public void jetPrint() throws JetException {
// codes for generating the report contents.
// ...
}
}

Then, in your main program, create a JetWriter instance and pass an instance of your report class to the JetWriter with the function jetRunReport():

JetWriter jw = new JetWriter();
// optionally set the print job attributes here.
jw.jetRunReport(new ProductList());

Then, the writer will call the codes in your report class in a background thread to generate the report.
How to preview a report.
The preview service can be easily employed simply by activating it using a function:

JetWriter jw = new JetWriter();
...
jw.jetSetAutoPreview(true); // activate the preview service.

Alternatively, some constructors also allow the preview service to be set:

JetWriter jw = new JetWriter(true, false); // preview is activated; printer output is disabled.

Once activated, the library will automatically bring up a preview window when a few pages of the report are generated and ready to be shown. It does not need to wait for the entire report to be finished. This would be useful for reports that contain thousands of pages.
How to print AWT or Swing components.
The jetPrintComponent() family of functions can be used to print any AWT/Swing components. These functions allow the position and size of a component to be set. There are also specific functions to print JTable objects. For example:

JetWriter jw = new JetWriter();
jw.jetOpenReport();
JLabel mylabel = new JLable("Description");
jetPrintComponent(mylabel, 50, 100);
JTable mytable = new JTable(...);
jetPrintComponent(mytable, 100, 200, "80%", "80%");

Posted in Java | No Comments »

Marlons Report in Java

May 23rd, 2006 by pepesmith

Snippet daw ni strong

String headers = "Medina General Hospital";
String oz = "Ozamiz City";
String stdate = "Date";

JetWriter jw = new JetWriter(true, false);
jw.jetOpenReport();

Graphics2D g = jw.jetGetGraphics2D();

// g.drawString(headers, 220, 151);
g.drawString(headers, 221, 150);
g.drawLine(221, 152, 358, 152);
g.drawString(oz, 250, 170);
g.drawString(tDate.toString(), 350, 200);
g.drawLine(340,201, 450, 201);
g.drawString(stdate,380,213);
g.draw3DRect(130,130, 335, 335, false);
g.drawString(dcCharge, 221,225);
g.drawString(csnum.toString(),150, 250);
g.drawString(cs.toString(), 340,250);
g.drawString(csT.toString(), 340, 280);

jw.jetCloseReport();

Posted in Java | No Comments »

« Previous Entries