Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8540121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:31:36+00:00 2026-06-11T11:31:36+00:00

EDIT4: I don’t know why, but the structure I used below didn’t work. I

  • 0

EDIT4:

I don’t know why, but the structure I used below didn’t work. I had to modify a file I found at java2s website, it’s called TableFromDatabase, then make the JTextFields public static, then instantiating the TableFromDatabase class in FrmMovimento and etc:

TableFromDatabase frame = new TableFromDatabase();
jDesktopPane2.add(frame);
frame.show();

I also modified TableFromDatabase line

frame.setDefaultCloseOperation( EXIT_ON_CLOSE_ );

to

frame.setDefaultCloseOperation( DISPOSE_ON_CLOSE );

ORIGINAL POST:

In this part of the program, the JInternalFrame file FrmMovimento, I made a button called Visualizar (“View”). Based on what we type on the text fields, it must show the interval the user defined.

There are these JTextFields:
Code from: _ To: _
Asset: _

And these JFormattedTextFields:
Date from: _ To: _

There are registers appearing already in the JDesktopPane from JInternalFrame FrmListarMov, if I use another SELECT statement selecting all registers, for example. But not if I type as I did in the title:

public List<MovimentoVO> Lista() throws ErroException, InformacaoException{
    List<MovimentoVO> listaMovimento = new ArrayList<> ();
    try {

        MySQLDAO.getInstancia().setAutoCommit(false);
        try (PreparedStatement stmt = MySQLDAO.getInstancia().prepareStatement(
             "SELECT * FROM Cadastro2 WHERE Codigo BETWEEN "+ txtCodDeMov +" AND "+ txtCodAteMov +";") {

            ResultSet registro = stmt.executeQuery();

            while(registro.next()){

                MovimentoVO Movimento = new MovimentoVO();

                Movimento.setCodDeMov(registro.getInt(1));
                Movimento.setCodAteMov(registro.getInt(2));
                Movimento.setAtivoMov(registro.getString(3));
                Movimento.setDataDeMov(registro.getString(4));
                Movimento.setDataAteMov(registro.getString(5));

                listaMovimento.add(Movimento);
            }
        }
    } catch (SQLException ex) {            
          throw new ErroException(ex.getMessage());
     } catch (InformacaoException ex) {  
          throw ex;
    }
    return listaMovimento;
}

In the SELECT line, txtCodDeMov is how I named the JTextField of “Code from” and txtCodAtemov is how I named the JTextField of the first “To”.

Oh, I’m using NetBeans 7.1.2 (Build 201204101705) and MySQL Ver 14.14 Distrib 5.1.63 in a Linux Mint 12 64-bits.

EDIT: actually, it’s MovimentoVO2, MovimentoDAO2 and so on, because I did two files, one with setCodDeMov and setCodAteMov etc. and another one with only setCodigo, setAtivo and setData. I’m still kind of noob in using these techniques, sorry.

From table Cadastro2, only primary key Codigo will be used for the query.
Later we’ll create other table where we’ll register buy and sell of assets, so they’ll have the type of asset and movement date, which will be added to the SELECT … BETWEEN … AND we need. By now, I need only to understand how Java could get the value I typed in the JTextField and put it into the SELECT command.

EDIT2: In the client registration screen, query button is working 100%, as follows. BUT it’s a different situation, since in this case the button event makes all JTextFields to be completed if the register with specified Code (primary key in the table Cadastro2) is found. Now what I want to do is produce a table with all the registers in the interval.

EDIT3: I think the correct term is REPORT GENERATING. I heard about iReport and Jasper Reports, but I never used them. Considering this project must be presented in December in the university, is there time to learn these 2 tools? As I’m learning Java still, would it be a bad move? At first I think it is, so I’m doing everything only on Netbeans.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:31:37+00:00Added an answer on June 11, 2026 at 11:31 am

    don’t use dynamic sql, it causes SQL injection. Use parameters.

    replace
    "SELECT * FROM Cadastro2 WHERE Codigo BETWEEN "+ txtCodDeMov +" AND "+ txtCodAteMov +";"

    to

    "SELECT * FROM Cadastro2 WHERE Codigo BETWEEN ? AND ?" // without semicolon in query
    ...
    stmt.setString(1, txtCodDeMov); // depends of 'Codigo' type, it may be stmt.setLong(1, txtCodDeMov);
    stmt.setString(2, txtCodAteMov);
    ResultSet registro = stmt.executeQuery();
    

    EDIT:
    and don’t get fields value by index if you don’t specify fields order in query. You can change fields order in database later, and your function will return incorrect rusult.
    Get values by field name or specify fileds order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I've found what's causing the issue, but I don't know why and I
EDIT I don't know is it important, but destination triangle angles may be different
EDIT 1 I apologize but after reading the 2 suggested articles I still don't
I want to post on twitter wall but don't want that user can edit
At work we found that on some instances (particulary the slow ones) we have
EDIT : I don't know in advance at which column my digits are going
edit : I don't get any errors anymore, but executing this code: $(#button-container).append(.tbox); only
I don't know why I'm having so much trouble searching this, it seems really
I know I shouldn't be using that function, and I don't care. Last time
EDIT: I don't what I did that is different from what i wrote below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.