Change the Column in Table using Alias in Java Tutorial

0
24

Change the Column in Table using Alias in Java Tutorial

Sometimes the names of columns are so technical that make the query’s output very difficult to understand. To give a column a descriptive name, you use a column alias.

This is all about Change the Column in Table using Alias in Java Tutorial. In this tutorial you will learn how to Change the Column in Table using Alias in Java Tutorial to make it more readable. It allows you to set your own title and display in the table. This tutorial uses table component in java and Netbeans IDE. Please follow all the steps below to complete this tutorial.

 

Change the Column in Table using Alias in Java Tutorial steps

First, you need to create a project by right clicking the file at the top left of the netbeans IDE and by selecting New Project you can name your project whatever you want, and then create your jframe form by right clicking the Source Packages and select New JFrame Form. After creating the form drag a table component in your form.

And then copy paste the code below and paste it inside initComponents Function

 

  1. try{
  2.  
  3. String sql = "SELECT product_name AS 'Product Name',company_name AS 'Company Name',date_of_sale AS 'Date Purchased',quantity AS 'Quantity',amount AS 'Amount' FROM sales_record";
  4.  
  5. pst = conn.prepareStatement(sql);
  6.  
  7. rs = pst.executeQuery();
  8.  
  9. if (rs.next()){
  10.  
  11. tablename.setModel(DbUtils.resultSetToTableModel(rs));
  12.  
  13. }
  14.  
  15. }catch(Exception e){
  16.  
  17. JOptionPane.showMessageDialog(null, e);
  18.  
  19. }

Then you’re done, run your project and see if it works.

Note the AS keyword is what make the alias work, it changed the column name in order to give a much more descriptive name.

For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: [email protected]

Facebook: facebook.com/RyyanSalem

Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

System Analyst / System Developer

Related topic(s) that you make like:

1.) How to use Scanner in Java Tutorial using Netbeans IDE
2.) Create Beautiful Bar Chart in Java Tutorial using Netbeans IDE

Facebook Comments
(Visited 35 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here