Problem and its Solution in SQL Query: How to solve If database table field is blank or null then replace or fill it with zero (0) or one (1) without using if condition in query||Solution procedure of if field = blank or Null then field =0 or 1


sql query

Have you ever faced a problem while using SQL Query in your software where you have to replace the blank or null field in database table with “0”  or  “1”  but  you are  unable to use “If condition” in the sql?


Here I have got a solution where you can replace  or fill the blank or null table data with “0” or “1” by using COALESCE   in SQL query.
 

Let us assume we have a table called “ITEM”   and it has four fields named “ order_no”, “item_no”, “qty” and  “style_sample_no” . In the field “style_sample_no” there is no data i.e.  this filed is blank/null or empty.

  Read more of this post

Java Xml file to Jasper converter : How to convert Xml file into Jasper in Java using jasper-compiler, jasper-runtime and jasper_bundle||Source code example included.


xml to jasper javaFor the reporting purpose sometimes we may need to convert xml file into jasper.

Here I have tried to show you the conversion procedure of xml file to jasper file using Java Programming Language.

To do this you need the following jar (drivers actually) files

1. jasper-compiler.jar
2. jasper-runtime.jar
3. jasper_bundle.jar

Below, I have attached the Java Source Code of XML to JASPER Converter, Code to compile and run the source code. Also I have included an Image to show you the whole procedure.

Read more of this post

Solution of Batch entry 0 insert into postgresql database table, Call getNextException to see the cause|| Learn How to solve this exception or error ||Java PostgreSQL Database Exception.


sun javaHave you ever faced this exception while executing sql query in  your software  or  database?? Well, I am using  Java programming language in the front end and PostGreSQL in the backend i.e. server side. Recently I have faced the following  exception which was showing actually from the database. I searched internet for the solution but didn’t get any reliable solution. But at last I have solved it and sharing the solution procedure with you. Hope it will also work with your problem

Here is the problem (Exception)

Batch entry 0 insert into endproduct_mat_req(item_no,end_product_mat_no,mat_no,qty) values(523,71,44,100000.0) was aborted.  Call getNextException to see the cause

Read more of this post

Java HashMap Key Set to String ,Array or Vector Convert: Use multiple type (String or Integer) data together as Key Value|| Procedure to retrieve (show) or get individual values from the multiple data type Hash Map key by splitting or breaking || next convert the key into vector.


hashmap key to vector or string array

After a long time I am sharing a post related to Java Programming language. Recently, I have faced a problem while coding   on java HashMap key value set on my job. In my last post I have shown How to show Java HashMap Key value pair and work on it. But the problem I have faced is to convert the Key value set to Vector or String. I used two (2) integer type data, separated with colon, as the key value of my HashMap.  What I need to convert that colon separated key values to individual integer and then convert them or stored them on Vector.

The program given below will show you how to solve such situation.

Read more of this post

JButton in JTable Cell: How to add, assign or fill up JTable’s Cell with JButton and then add ActionListener to enable Click event for that JButtons in JTable cell.


JButton in JTable cellSometimes while working with software using java programming language we may face problem while working with JTable. In JTable Cell you may need to show JButton for various purposes. So, to show JButton in JTable Cell or to fill up JTable’s Column with JButton you will need to use ButtonRenderer and ButtonEditor and to add Click Event on the JButton in JTable cell you will need to add ActionListener for that JButton.

Just Copy the code Below and run it and change it according to your need.

Read more of this post

JTable Cell Empty Validation: How to check or know JTable cell is empty or not and also avoid null or space entry validation in JTable cell before saving JTable data in Database


JTable empty cell validation While designing or preparing  software you may face problem  to check  JTable cell is empty or not while entering JTable data in Database. Another thing may happen, suppose you are trying to validate your JTable cell empty or not but it is taking space or null entry as a string and your empty cell validation may not work. Here I am sharing you a little but useful technique by which you will be able to check your empty JTable cell and also if you enter space in the JTable cell it will catch this cell as empty and will show error. Just run the given program and check how it works.

  Read more of this post

Java English to Bengali (Bangla) Dictionary: How to read or search Bengali word from a file or notepad and then show it in JTextField.


English to bengali dictionary javaToday I am sharing with you another important topic where I will give you an example by which you will get a clear idea about how to read or search any Bengali or Bangla font from a text pad (notepad) or file and then show it in JTextField. This code is important for those who are trying to prepare English to Bengali Dictionary. Download the reader.txt which I have used here to read Bengali (Bangla) words.

 
Copy the following code and run it by keeping reader.txt in the same folder.

Java Vector Numeric value and SQL Query: How to use Numeic or integer values of a vector in SQL and also how to execute them.


use Vector numeric or integer  value in sql using javaSometimes we may need to use the value of a vector mainly the integer or numeric value in SQL to execute a query . Suppose you have a vector named   studentAge which contains two numeric value for example: [10,12]. Now, if you want to use these two vectors in the SQL to for query execution then you have to write the query as given below.

String sql=”select student_name from student where student_age in (” + studentAge .toString().substring(1, studentAge.toString().lastIndexOf(“]”))+”) and student_class =”+student-class;

Just You have to use the following line

(” + studentAge.toString().substring(1, studentAge.toString().lastIndexOf(“]”))+”)

 

Read more of this post

Java HashMap Key Value Pair: How to show the Key Value pair data of HashMap.


hashmap key value pair data javaSometimes in java while we do coding and use HashMap we may need to check or see the values reside in Key and their corresponding Data or Values at the same time. Here I am sharing you another simple but useful technique to see the key value pair data of HashMap at a time. Just copy the code below and run it on your computer.

Read more of this post

Java break string in into individual words: How to split a string according to space,comma, colon and more between them and then save it in an array of string.


split string into words and string manipulationToday I am sharing you another basic but important technique about string manipulation. While coding in java, sometimes we need to split or break a string into individual word according to space, commas, colon or any other character between them and then save that individual words into an array of string.

The coding is simple and you can test it according to your need. Just copy the code below and run it in your own machine. Please give comments if this solution is helpful for you.

Read more of this post

Java String Manipulation: How to search or match any given word in a string and then replace that word


search a word in a string and then replace javaHere, I am sharing you another basic technique about java where I have searched a word in a String and then replace it by another word. In this technique I have avoided case differences (avoiding upper case or lower case letter difference). From this example you will be able to know about

  1. How to search any specific word in a string
  2. 

  3. How to avoid case difference  while searching a word in a string using java
  4. How to replace any specific word ignoring case difference.

 

Read more of this post

Java JButton Click event and JTable: Click on the JButton and the JTable will show or appear


Here I am sharing you a simple but useful way about JButton and JTable. Sometimes in designing   software, where we are using JButton and JTable, we may need to code or design in such a way that just user will click on the JButton (by using JButton ActionListener) and the JTable will show or appear with its value. Copy the code below and run on your computer.

Read more of this post

Java JButton below the JTable: How to use and place JButton just under or beneath the JTable.


JBUtton below the JTableHere I am sharing with you another simple but important  fact related to  java JTable and JButton. If you are using JButton and JTable in your software, it may need to place your JButton just under or below the JTable. Here I have shown the way how to place JButton just beneath the JTable. Just copy the code below and run in your pc.

Here is the Code:   JButton Just Below or beneath the JTable

Read more of this post

JTable Cell Validation: How to make Cells of first Column will take Char (string)input other Cells of second column will take int (integer ) input.


Two different JTable Cell two different inputIn my last post  I shared  about how to assign two different JTextField in two different JTable Column cells. Today I am sharing with you  another important part of  JTable cell validation where I have tried to show you about how to make  first column of JTable cells take only Char or string input and also at the same time  how to make the  cells second column  take int (integer ) input from the users. To implement this validation process I have assigned two different JTextField in two different JTable Cell Column. Just Copy the following code and Run it in your pc.

Read more of this post

JTable Cell Edit for validation: How to assign two Different JTextField in two different JTable Column Cells.


Two JTextField in two different Table Column cellThis post is also related to JTable cell validation, suppose our JTable has 3 columns.  First column will take String or character type input and the second column or Column 2 will take integer type input from users. So, if we want to implement this scenario in our software we can solve it by assigning or using two different JTextField  for the cells of  Column 1 and Column 2 in JTable. In our example we used textBox1 (JTextField) in Column 1, which will  validate string or char type input from users and  for Column 2  I have assigned    textBox (JTextField) to validate int type input from the users.  The given solution is just a basic you can implement it as your own way.  Just Copy the following code and run it.

 

Read more of this post

Java JTable Cell and JTextField: How to use and assign JTextField in JTable cell.


I think, to assign a JTextField in JTable cells is really important for the purpose of JTable cell validation. For many purpose in software development where we use JTable may need to use JTable cell validation  and for this validation purpose we may also need to assign and use JTextField in JTable cell. In the given Example, I have assigned and used  a JTextField  in the  Column 2  of the following JTable. Just Copy the code and Run it in your computer.

Read more of this post

JTable Cell Validation: How to make JTable Cell allow or accept only integer (numeric) number/data.


JTable Cell ValidationSometimes in programming while we do our work with JTable cell, we may need to make the JTable cell Such that it will allow or accept only numeric or number type data from users and will not allow any other type of data in that cell. In the following example(Check the picture), I have made the cells of Column-2 such that  they will allow only numeric data and it will show a warning message if   any character or string type entry is detected.  Just Copy the code and run it.

JTable cell Color: How to color your JTable individual cell background.


JTable Individual cell colorHere I am going to share with you a little solution by which you can color the background of individual JTable cell. In the following code I colored the cell’s background in click event i.e when you will click on the JTable Cell the background of that cell will be red. This solution is just to give you a basic idea; you can modify it as your own.  The code is given below.

 

Read more of this post

JTable Cell Click Event: Click on the JTable Cell and show the Value of that cell.


Sometimes while programming we may need to check and show the value of JTable Cell in click event.

Here, in the given example, I did the coding in such a way that while clicking on a cell of  JTable

It will show the value of that JTable cell in MessageDialog Box.

Code Example:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

class SimpleTableTest extends JFrame

                {

private JPanel topPanel ;

private JTable table;

private JScrollPane scrollPane;

private String[] columnNames= new String[3];

private String[][] dataValues=new String[3][3] ;
Read more of this post

Java :How to know in which Row and Column I have clicked on JTable


In this post I have shared you the solution about how to know in which Row and Column of JTable I have clicked.

According to the solution, wherever you have clicked on the JTable the result will be shown using

Message Dialog Box (Check the OUTPUT picture below).

 

Code Example:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.table.*;

class SimpleTableTest extends JFrame

                {

private JPanel topPanel ;

private JTable table;

private JScrollPane scrollPane;

private String[] columnNames= new String[3];

private String[][] dataValues=new String[3][3] ;

public SimpleTableTest()

    {

setTitle(“JTable Cell Click”);

setSize(300,300);

topPanel= new JPanel();

topPanel.setLayout(new BorderLayout());

getContentPane().add(topPanel);

setDefaultCloseOperation(EXIT_ON_CLOSE);

columnNames=new String[] {“Column 1” , “Column 2” , “Column 3”};

 dataValues = new String[][]   {

                                    {“1″,”2″,”3”},

                                    {“4″,”5″,”6”},

                                    {“7″,”8″,”9″}

                                          };

 TableModel model=new myTableModel();

 table =new JTable( );

 table.setRowHeight(50);

 table.setModel(model);

 scrollPane=new JScrollPane(table);

  topPanel.add(scrollPane,BorderLayout.CENTER);   

  table.addMouseListener(new java.awt.event.MouseAdapter()

            {

public void mouseClicked(java.awt.event.MouseEvent e)

{

int row=table.rowAtPoint(e.getPoint());

int col= table.columnAtPoint(e.getPoint());

JOptionPane.showMessageDialog(null,”You have Clicked on Column :” +(col+1)+ ” : and Row : ” +(row+1));

System.out.println(table.getValueAt(row,col).toString());

}

}

);

}

            public class myTableModel extends DefaultTableModel

                                                {

                                                    myTableModel( )

                                                 {

                                                  super(dataValues,columnNames);

                                                  System.out.println(“Inside myTableModel”);

                                                 }

                                                public boolean isCellEditable(int row,int cols)

                                                 {

                                   return false;                                                                                         

                                                }

                                                }         

            public static void main(String args[])

            {

            SimpleTableTest mainFrame=new SimpleTableTest();

            mainFrame.setVisible(true);

            }         

                 }
OUTPUT:

JTable Row and Column Click