This a question please

schools     grades
-------    --------
havard       90%

with this table, i want to select the information in each column concatenate them and ouput the results in a textfeild.
sample output = havard/90%

so can you declare a column in mysql as a variable in java?
if yes then please attach some examples thank you.

Recommended Answers

All 10 Replies

You have to execute a SELECT statement via Java's JDBC SQL support, then you get a ResultSet that contains the data in Java variables.
Just Google for JDBC tutorials

This code displays this string FC/SW/OE/SW/100
based on the selection of the 'Desc Code'(combobox) and 'item Code'(combobox)

 String procedure;
    String efault = "FC";
    String db_trial;
    String iCode; 



 ComboBox_itemCode.addItemListener(new ItemListener(){
        public void itemStateChanged(ItemEvent arg0) {
            // Combine your different comboboxes here
            iCode =(String)ComboBox_itemCode.getSelectedItem();              
            procedure = (String) ComboBox_decCode.getSelectedItem();
         txt_sn.setText(efault.concat("/").concat(procedure).concat("/").concat(iCode));


        }
    });

this is a method i wrote to select the items in the columns of my database which you told me to but it gives me all the data under that column instead of one.

public void veiwTable(){
    try{
        String sql = "select Description_Code from items";
        pst=conn.prepareStatement(sql);
        rs = pst.executeQuery(sql);

         while (rs.next()) {
         String descCode = rs.getString("Description_Code");


            System.out.println(descCode);




        }

    }catch(Exception e){
        JOptionPane.showMessageDialog(null,e);
    }
}

the idea is if i select 'desc code' and 'item code' from my app it should add descCode from my database to the results by way of concatenation.

i hope my problem is clear

i wanted to add an image but it seems that is not allowed

It seems you have not yet covered how to use SQL to select or update data. The Java support and tutorials all assume you alreadfy know the required SQL. Maybe a web tutorial on simple SQL for beginners would help at his stage?

ps: You can add images to a database, retrieve them, and display them, all from Java. But maybe you should master doing it with Strings first.

i was saying i wanted to add an image to my post so that u can understand my problem very well

Oh, OK. There's a "Files" button at the top of the text entry box (between List and Undo). Just click on that and browse to your image file.
a9ab3e458e33b329c30abc1e4b09b9ce

so when i select 'desc Code' it should appear in item code in this form
MV/

so in this case LB/
i wrote this to do that but it is giving me redundancy
instead of showing only 'LB/',it shows more than one 'LB/'
so now how can i make it show only the one selected item
and when i select another item in 'desc code' it should change in the 'item code' too

i hope this makes my question clearer

  • this question is about business rules, logics not about Java & JDBC,

  • by default most of profesional apps for trading has very similair structure and concept

@mKorbel i hope u get my question?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.