ElaKiri Programmer's Club

thilihare

Well-known member
  • Apr 30, 2013
    6,683
    741
    113
    Kandy
    වැඩ්ඩනි පොඩි help එකක් ඕනි

    JAVA

    ComboBox 2ක් link කරගන්න ඕනෙ. එකක තියෙන්නේ itemCategory ටික. අනිකේ තියෙන්නේ ඒ ඒ category එකට තියෙන item ටික.

    2076byb.png


    Item Category ටික තියෙන්නේ වෙනම table එකක. Item ටික තියෙන්නේ වෙනම table එකක.

    2wgzwq1.png


    මං form එක Load වෙද්දී itemCategory ටික මුල් combo එකට එන්න code එක ලියාගත්තා.

    Code:
     void loadcomboCatInv(){
            try {
                ResultSet rs = db.getData("SELECT cat_name FROM itemcategory");
                    Vector v = new Vector();
                    while(rs.next()){
                        v.add(rs.getString("cat_name"));
                        comboCatInv.setModel(new DefaultComboBoxModel(v));
                    }
    දැන් ඕනෙ මුල් combo එකෙන් category එක තේරුවාම ඒ categoryID එක තියෙන item ටික යට combo එකෙන් එන්න ඕනෙ. මට අවුල තියෙන්නේ මුල් combo එකෙන් මං තෝරන්නේ item category එක text එකක් විදියට. එතකොට පලවෙනි combo එකෙ උඩ click උනාම මට ඕනෙ ඒ select කරපු category text එකට අදාල categoryID එක තියෙන item ටික දෙවෙනි combo එකෙන් ගන්න. ටිකක් අවුල් වගේ අප්පා. පොඩි help එකක් දෙනවද :sorry:

    mekata karanna oni mehemaiii
    Action i liyanna oni combo 1 itemStatechange acction 1 ta Ekedi state change 1 una gaman Eke select wela thiyana text 1 k th ekka search 1 gahanna eta passe items load karanna 2 weni combo 1 ta

    Pahadili madi nam kiyanna code 1 gahala ewannam habaii hawasata
     

    KingCM

    Well-known member
  • Jul 23, 2013
    6,920
    948
    113
    www.biogen.lk
    වැඩ්ඩනි පොඩි help එකක් ඕනි
    ........................................
    Item Cගන්න. ටිකක් අවුල් වගේ අප්පා. පොඩි help එකක් දෙනවද :sorry:

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    public class Compare extends JFrame implements ItemListener {
            JComboBox combo, lcombo;
     
            public Compare() {
                    setLayout(null);
                    String a[] = { "Select", "Watches", "Mobiles", "shoes" };
                    combo = new JComboBox(a);
                    combo.setBounds(50, 50, 100, 20);
                    combo.addItemListener(this);
                    add(combo);
     
                    lcombo = new JComboBox();
                    lcombo.addItemListener(this);
                    lcombo.setEnabled(false);
                    add(lcombo);
                    lcombo.setBounds(50, 100, 100, 20);
     
                    setSize(300, 300);
            }
     
            public void itemStateChanged(ItemEvent e) {
                    String b[] = { "Titan", "HMT" };
                    String c[] = { "Nokia", "Sony", "Motorola", "Samsung" };
                    String d[] = { "Liberty", "Action", "Bata", "Campus", "Relaxo" };
     
                    if (e.getSource() == combo) {
                            if (combo.getSelectedItem().equals("Select")) {
                                    lcombo.setEnabled(false);
                            } else if (combo.getSelectedItem().equals("Watches")) {
                                    lcombo.setEnabled(true);
                                    lcombo.removeAllItems();
                                    for (int i = 0; i < b.length; i++) {
                                            lcombo.addItem(b[i]);
                                    }
                            } else if (combo.getSelectedItem().equals("Mobiles")) {
                                    lcombo.setEnabled(true);
                                    lcombo.removeAllItems();
                                    for (int i = 0; i < c.length; i++) {
                                            lcombo.removeItem(c[i]);
                                            lcombo.addItem(c[i]);
                                    }
                            } else if (combo.getSelectedItem().equals("shoes")) {
                                    lcombo.setEnabled(true);
                                    lcombo.removeAllItems();
                                    for (int i = 0; i < d.length; i++) {
                                            lcombo.addItem(d[i]);
                                    }
                            }
                    }
            }
     
            public static void main(String args[]) {
                    (new Compare()).setVisible(true);
            }
    }
    or

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    
    public class ComboBoxTwo extends JFrame implements ActionListener
    {
        private JComboBox mainComboBox;
        private JComboBox subComboBox;
        private Hashtable subItems = new Hashtable();
    
        public ComboBoxTwo()
        {
            String[] items = { "Select Item", "Color", "Shape", "Fruit" };
            mainComboBox = new JComboBox( items );
            mainComboBox.addActionListener( this );
    
            //  prevent action events from being fired when the up/down arrow keys are used
    //      mainComboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
            getContentPane().add( mainComboBox, BorderLayout.WEST );
    
            //  Create sub combo box with multiple models
    
            subComboBox = new JComboBox();
            subComboBox.setPrototypeDisplayValue("XXXXXXXXXX"); // JDK1.4
            getContentPane().add( subComboBox, BorderLayout.EAST );
    
            String[] subItems1 = { "Select Color", "Red", "Blue", "Green" };
            subItems.put(items[1], subItems1);
    
            String[] subItems2 = { "Select Shape", "Circle", "Square", "Triangle" };
            subItems.put(items[2], subItems2);
    
            String[] subItems3 = { "Select Fruit", "Apple", "Orange", "Banana" };
            subItems.put(items[3], subItems3);
            mainComboBox.setSelectedIndex(1);
        }
    
        public void actionPerformed(ActionEvent e)
        {
            String item = (String)mainComboBox.getSelectedItem();
            Object o = subItems.get( item );
    
            if (o == null)
            {
                subComboBox.setModel( new DefaultComboBoxModel() );
            }
            else
            {
                subComboBox.setModel( new DefaultComboBoxModel( (String[])o ) );
            }
        }
    
        public static void main(String[] args)
        {
            JFrame frame = new ComboBoxTwo();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible( true );
         }
    }
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,860
    1
    9,621
    113
    Gampaha
    වැඩ්ඩනි පොඩි help එකක් ඕනි

    JAVA

    ComboBox 2ක් link කරගන්න ඕනෙ. එකක තියෙන්නේ itemCategory ටික. අනිකේ තියෙන්නේ ඒ ඒ category එකට තියෙන item ටික.

    2076byb.png


    Item Category ටික තියෙන්නේ වෙනම table එකක. Item ටික තියෙන්නේ වෙනම table එකක.

    2wgzwq1.png


    මං form එක Load වෙද්දී itemCategory ටික මුල් combo එකට එන්න code එක ලියාගත්තා.

    Code:
     void loadcomboCatInv(){
            try {
                ResultSet rs = db.getData("SELECT cat_name FROM itemcategory");
                    Vector v = new Vector();
                    while(rs.next()){
                        v.add(rs.getString("cat_name"));
                        comboCatInv.setModel(new DefaultComboBoxModel(v));
                    }
    දැන් ඕනෙ මුල් combo එකෙන් category එක තේරුවාම ඒ categoryID එක තියෙන item ටික යට combo එකෙන් එන්න ඕනෙ. මට අවුල තියෙන්නේ මුල් combo එකෙන් මං තෝරන්නේ item category එක text එකක් විදියට. එතකොට පලවෙනි combo එකෙ උඩ click උනාම මට ඕනෙ ඒ select කරපු category text එකට අදාල categoryID එක තියෙන item ටික දෙවෙනි combo එකෙන් ගන්න. ටිකක් අවුල් වගේ අප්පා. පොඩි help එකක් දෙනවද :sorry:
    මට හිතෙන විදියටකියන්නම්..
    1.මුලින්ම ඔයාගේ ඔය තියෙන ටේබල් දෙක වැරදියි. item category වෙනම ටේබල් එකක තියාගන්නව නම් ඒක foreign key කරල reference එක තියාගන්න. නැතුව ආයිත් item category එක items table එකේ තියාගන්න එක තේරුමක් නෑ. එහෙම නැත්නම් item category table එක අයින් කරල DISTINCT keyword එක use කරන්න.

    2.
    SELECT item_name FROM items WHERE item_category = '"+comboCatInv.getSelectedItem()+"' ORDER BY item_name

    3.Events

    private void
    comboCatInvPopupMenuWillBecomeInvisible(){
    }

    or

    private void comboCatInvItemStateChanged(){
    }

    4.Validate

    if(
    comboCatInv.getModel().getSize() > 0){
    }

     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,860
    1
    9,621
    113
    Gampaha
    HELP BUMP!! :(
    බලන්න මේක හරියනවද කියල.

    Skaters Class

    Code:
    import java.util.Arrays;
    import java.util.Objects;
    
    /**
     *
     * @author MihiCherub
     */
    public class Skaters {
    
        private String name1;
        private String name2;
        private String country;
        private double[] arrTech = new double[8];
        private double[] arrPerf = new double[8];
        private double score;
    
        public Skaters() {
        }
    
        public String getName1() {
            return name1;
        }
    
        public void setName1(String name1) {
            this.name1 = name1;
        }
    
        public String getName2() {
            return name2;
        }
    
        public void setName2(String name2) {
            this.name2 = name2;
        }
    
        public String getCountry() {
            return country;
        }
    
        public void setCountry(String country) {
            this.country = country;
        }
    
        public double[] getArrTech() {
            return arrTech;
        }
    
        public void setArrTech(double[] arrTech) {
            this.arrTech = arrTech;
        }
    
        public double[] getArrPerf() {
            return arrPerf;
        }
    
        public void setArrPerf(double[] arrArt) {
            this.arrPerf = arrArt;
        }
    
        public double getScore() {
            return score;
        }
    
        public void setScore(double score) {
            this.score = score;
        }
    
        @Override
        public boolean equals(Object object) {
            if (object == null) {
                return false;
            }
            if (getClass() != object.getClass()) {
                return false;
            }
            final Skaters other = (Skaters) object;
            return this.hashCode() == other.hashCode();
        }
    
        @Override
        public int hashCode() {
            int hash = 7;
            hash = 71 * hash + Objects.hashCode(this.name1);
            hash = 71 * hash + Objects.hashCode(this.name2);
            hash = 71 * hash + Objects.hashCode(this.country);
            hash = 71 * hash + Arrays.hashCode(this.arrTech);
            hash = 71 * hash + Arrays.hashCode(this.arrPerf);
            hash = 71 * hash + (int) (Double.doubleToLongBits(this.score) ^ (Double.doubleToLongBits(this.score) >>> 32));
            return hash;
        }
    }

    SkaterRecords Class


    Code:
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Objects;
    
    /**
     *
     * @author MihiCherub
     */
    public class SkaterRecords {
    
        private final List<Skaters> list;
    
        public SkaterRecords() {
            list = new ArrayList<Skaters>();
        }
    
        public boolean addRecord(Skaters skaters) {
            return list.add(skaters);
        }
    
        public int getTotalRecords() {
            return list.size();
        }
    
        public void removeAllFrom(int index) {
            //Captures the beginning of where u specify 'index' to the end and clears it 
            list.subList(index, list.size()).clear();
        }
    
        public void removeAllUpto(int index) {
            //Captures the beginning '0' up to where u specify 'index' and clears it 
            list.subList(0, index).clear();
    
        }
    
        public void printRecord() {
            for (Skaters skater : list) {
                System.out.println("Name1: " + skater.getName1());
                System.out.println("Name2: " + skater.getName2());
                System.out.println("Country: " + skater.getCountry());
    
                double[] arrTech = skater.getArrTech();
                for (double value : arrTech) {
                    System.out.print(value + " ");
                }
                System.out.println("");
    
                double[] arrPerf = skater.getArrPerf();
                for (double value : arrPerf) {
                    System.out.print(value + " ");
                }
                System.out.println("");
    
                System.out.println("Score: " + skater.getScore());
                System.out.println("");
            }
        }
    
        public Skaters getWinner() {
            double max = 0;
            Skaters winner = null;
            for (Skaters skater : list) {
                if (max < skater.getScore()) {
                    max = skater.getScore();
                    winner = skater;
                }
            }
            return winner;
        }
    
        @Override
        public boolean equals(Object object) {
            if (object == null) {
                return false;
            }
            if (getClass() != object.getClass()) {
                return false;
            }
            final SkaterRecords other = (SkaterRecords) object;
            return this.hashCode() == other.hashCode();
        }
    
        @Override
        public int hashCode() {
            int hash = 7;
            hash = 71 * hash + Objects.hashCode(this.list);
            return hash;
        }
    
    }

    Main Class

    Code:
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
    
    /**
     *
     * @author MihiCherub
     */
    public class TestSkaters {
    
        private static SkaterRecords skaterRecords;
    
        public static void main(String[] args) throws FileNotFoundException {
            skaterRecords = new SkaterRecords();
            readFile();
    
            skaterRecords.printRecord();
            Skaters winner = skaterRecords.getWinner();
            System.out.println("Medal Winners :");
            System.out.println("Name1: " + winner.getName1());
            System.out.println("Name2: " + winner.getName2());
            System.out.println("Country: " + winner.getCountry());
            System.out.println("Score: " + winner.getScore());
        }
    
        private static void readFile() throws FileNotFoundException {
            File file = new File("Pairs.txt");
            Scanner input;
            if (file.exists()) { // FileNotFoundException Handle 
                input = new Scanner(file);
                while (input.hasNext()) {
    
                    Skaters skater = new Skaters();
                    skater.setName1(input.nextLine());
                    skater.setName2(input.nextLine());
                    skater.setCountry(input.nextLine());
    
                    double sum = 0;
    
                    final double tech[] = new double[8];
                    for (int i = 0; i < 8; i++) {
                        tech[i] = input.nextDouble();
                        sum += tech[i];
                    }
                    skater.setArrTech(tech);
    
                    final double perf[] = new double[8];
                    for (int i = 0; i < 8; i++) {
                        perf[i] = input.nextDouble();
                        sum += perf[i];
                    }
                    skater.setArrPerf(perf);
                    skater.setScore(sum / 2);
                    skaterRecords.addRecord(skater);
    
                    if (input.hasNextLine()) {
                        input.nextLine();
                    }
                }
                try {
                } finally {
                    input.close();
                }
            }
        }
    }

    අවුලක් තියෙනව නම් අහන්න.
    :D
     

    Voltage

    Well-known member
  • Feb 6, 2012
    21,723
    1
    15,120
    113
    thilihare

    KingCM

    MihiCherub


    අනේ Thanks මචන්ලා මම try එකක් දීල බලල කියන්නම්. Thanks a lot
     
    Last edited:

    Voltage

    Well-known member
  • Feb 6, 2012
    21,723
    1
    15,120
    113
    වැඩ්ඩනි පොඩි help එකක් ඕනි

    JAVA

    ComboBox 2ක් link කරගන්න ඕනෙ. එකක තියෙන්නේ itemCategory ටික. අනිකේ තියෙන්නේ ඒ ඒ category එකට තියෙන item ටික.

    2076byb.png


    Item Category ටික තියෙන්නේ වෙනම table එකක. Item ටික තියෙන්නේ වෙනම table එකක.

    2wgzwq1.png


    මං form එක Load වෙද්දී itemCategory ටික මුල් combo එකට එන්න code එක ලියාගත්තා.

    Code:
     void loadcomboCatInv(){
            try {
                ResultSet rs = db.getData("SELECT cat_name FROM itemcategory");
                    Vector v = new Vector();
                    while(rs.next()){
                        v.add(rs.getString("cat_name"));
                        comboCatInv.setModel(new DefaultComboBoxModel(v));
                    }

    දැන් ඕනෙ මුල් combo එකෙන් category එක තේරුවාම ඒ categoryID එක තියෙන item ටික යට combo එකෙන් එන්න ඕනෙ. මට අවුල තියෙන්නේ මුල් combo එකෙන් මං තෝරන්නේ item category එක text එකක් විදියට. එතකොට පලවෙනි combo එකෙ උඩ click උනාම මට ඕනෙ ඒ select කරපු category text එකට අදාල categoryID එක තියෙන item ටික දෙවෙනි combo එකෙන් ගන්න. ටිකක් අවුල් වගේ අප්පා. පොඩි help එකක් දෙනවද :sorry:

    thilihare

    KingCM

    MihiCherub


    අනේ Thanks මචන්ලා මම try එකක් දීල බලල කියන්නම්. Thanks a lot



    වැඩේ ගොඩ දාගත්ත මචන්. යන්තන් query එක ලියාගත්තා. දුකේ බෑ බන් වැඩ කරනවා ලෙසටම.

    MihiCherub thanks මචන් අතන මම table එකට වැඩිපුර field එකක් දාල මචන්. මට ඔයා කිවුවම තමයි මීටර් උනේ. ඒ table එකේ තියන අන්තිම field එකක මම FK කරල දාලා තිබුනෙ. දැන් වැඩේ හරි

    Query එක මීට වඩා අඩුවෙන් ලියන්න පුලුවන් ක්‍රමයක් තියෙනවද. මේ query එකෙන් නම් ඕන කරන result එක එනවා

    Code:
      int row = JtableCat.getSelectedRow();
                String selectedCat = JtableCat.getModel().getValueAt(row,0).toString();   
                
                            //CatName to CatID Query
                            ResultSet rsCatNameToId = db.getData(("SELECT cat_id FROM itemcategory WHERE cat_name='"+selectedCat+"'"));
                                while (rsCatNameToId.next()) {                
                                    int theCatId = rsCatNameToId.getInt("cat_id");
                                    //Main Search Query
                                ResultSet rsCat = db.getData("SELECT * FROM items WHERE itemCategory_cat_id='"+theCatId+"'");       
                                        DefaultTableModel dtmItems = (DefaultTableModel) JtitemTable.getModel();
                                        dtmItems.setRowCount(0);
                                            while (rsCat.next()){
                                                Vector vItem = new Vector();
                                                vItem.add(rsCat.getString("item_name"));
                                                vItem.add(rsCat.getString("item_qty"));
                                        dtmItems.addRow(vItem);
                                    }
                                
                                
                            }

     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,860
    1
    9,621
    113
    Gampaha






    වැඩේ ගොඩ දාගත්ත මචන්. යන්තන් query එක ලියාගත්තා. දුකේ බෑ බන් වැඩ කරනවා ලෙසටම.

    MihiCherub thanks මචන් අතන මම table එකට වැඩිපුර field එකක් දාල මචන්. මට ඔයා කිවුවම තමයි මීටර් උනේ. ඒ table එකේ තියන අන්තිම field එකක මම FK කරල දාලා තිබුනෙ. දැන් වැඩේ හරි

    Query එක මීට වඩා අඩුවෙන් ලියන්න පුලුවන් ක්‍රමයක් තියෙනවද. මේ query එකෙන් නම් ඕන කරන result එක එනවා

    Code:
      int row = JtableCat.getSelectedRow();
                String selectedCat = JtableCat.getModel().getValueAt(row,0).toString();   
                
                            //CatName to CatID Query
                            ResultSet rsCatNameToId = db.getData(("SELECT cat_id FROM itemcategory WHERE cat_name='"+selectedCat+"'"));
                                while (rsCatNameToId.next()) {                
                                    int theCatId = rsCatNameToId.getInt("cat_id");
                                    //Main Search Query
                                ResultSet rsCat = db.getData("SELECT * FROM items WHERE itemCategory_cat_id='"+theCatId+"'");       
                                        DefaultTableModel dtmItems = (DefaultTableModel) JtitemTable.getModel();
                                        dtmItems.setRowCount(0);
                                            while (rsCat.next()){
                                                Vector vItem = new Vector();
                                                vItem.add(rsCat.getString("item_name"));
                                                vItem.add(rsCat.getString("item_qty"));
                                        dtmItems.addRow(vItem);
                                    }
                                
                                
                            }

    මේ Query 1 මම උඩ එහෙන් පිටින්ම දීල තියෙනව දැක්කෙ නැතෙයි, :dull: නෝමලි ResultSet, Vector වගේ ඒවට වෙන නම් දාන්න යන්න එපා. form එකටම එකනෙ තියෙන්නෙ. ඒ නිසා ResultSet rs = ...; Vector v = ...; කියල use කරන්න. ඒක කෝඩ් එක පස්සෙ බලනකොට මාර ලේසියි.
     

    Voltage

    Well-known member
  • Feb 6, 2012
    21,723
    1
    15,120
    113
    Java | LoginForm

    මචන්ලා
    Java වලින් login form එකක් හදද්දි මං ඒකට පාවිච්චි කලේ JPasswordField එකක්. Db එකේ plain text වලින් password එක store කරන් නැති වෙන්න ඕන නිසා. save කලාම db එකේ encrypt වෙච්ච code එකක් වගේ මෙව්වා එකක් විදියට password එක save වෙනවා. ඒත් මම login form එකේ log වෙන code එකට password compare කරන්න try කලාට කරගන්න බෑනෙ. පොඩි help එකක් දෙනවද

    user ව save කරන code එක මම ලිවුවෙ මෙහෙම


    Code:
     String userName = txtuname.getText();
                    String userType;
                                    
                                                    if (JrAdmin.isSelected()) {
                                                           userType = "Admin";
                                                         } else if (JrCash.isSelected()) {
                                                           userType = "Cashier";
                                                         }else userType = "Owner";
                                                                                    
                       db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+txtupass.getPassword()+"')");

    login code එක මෙහෙම
    Code:
    String uname = txtUserName.getText();
            String pass = new String(txtPassword.getPassword());
            
                     
            ResultSet userset = db.getData("Select * from users where user_name='"+uname+"' and user_pw='"+pass+"'");
                    if(userset.next()) {
                  
                    dispose();
                    new mainUI().setVisible(true);

    database එකේ password එකට යන data type එක VARCHAR වලට දැම්මොත් නම් ඔය code එක වැඩ කරනවා. ඒත් plain text තියන එක අවුල් නිසා එකට මොකද්ද මචන්ලා කරන්න ඕන. database එකේ password එක තියන්න හොද මොන data type එකෙන්ද :sorry:
     
    Last edited:

    DJvodka

    Well-known member
  • Mar 31, 2009
    3,375
    292
    83
    A land like no other
    මචන්ලා
    Java වලින් login form එකක් හදද්දි මං ඒකට පාවිච්චි කලේ JPasswordField එකක්. Db එකේ plain text වලින් password එක store කරන් නැති වෙන්න ඕන නිසා. save කලාම db එකේ encrypt වෙච්ච code එකක් වගේ මෙව්වා එකක් විදියට password එක save වෙනවා. ඒත් මම login form එකේ log වෙන code එකට password compare කරන්න try කලාට කරගන්න බෑනෙ. පොඩි help එකක් දෙනවද

    user ව save කරන code එක මම ලිවුවෙ මෙහෙම


    Code:
     String userName = txtuname.getText();
                    String userType;
                                    
                                                    if (JrAdmin.isSelected()) {
                                                           userType = "Admin";
                                                         } else if (JrCash.isSelected()) {
                                                           userType = "Cashier";
                                                         }else userType = "Owner";
                                                                                    
                       db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+txtupass.getPassword()+"')");

    login code එක මෙහෙම
    Code:
    String uname = txtUserName.getText();
            String pass = new String(txtPassword.getPassword());
            
                     
            ResultSet userset = db.getData("Select * from users where user_name='"+uname+"' and user_pw='"+pass+"'");
                    if(userset.next()) {
                  
                    dispose();
                    new mainUI().setVisible(true);

    database එකේ password එකට යන data type එක VARCHAR වලට දැම්මොත් නම් ඔය code එක වැඩ කරනවා. ඒත් plain text තියන එක අවුල් නිසා එකට මොකද්ද මචන්ලා කරන්න ඕන. database එකේ password එක තියන්න හොද මොන data type එකෙන්ද :sorry:

    oka encrypt karala newei db ekata yanne. char[] array ekak widiyata. mysql database eke password ekata deela thiyena data type eka mokakd?

    Harinam password eka db ekata sha-256 ekakin salt ekak ekka hash karala thamai yawanne.
     

    Voltage

    Well-known member
  • Feb 6, 2012
    21,723
    1
    15,120
    113
    oka encrypt karala newei db ekata yanne. char[] array ekak widiyata. mysql database eke password ekata deela thiyena data type eka mokakd?

    Harinam password eka db ekata sha-256 ekakin salt ekak ekka hash karala thamai yawanne.

    VARCHAR තමයි මචෝ තියෙන්නේ. :dull:

    • user කෙනෙක් create කරන තැනයි
    • Login form එකෙයි
    password එක compare කරන්න ඕන code එක යන්තන් කියන්න පුලුවන්ද
    අනිත් ටික නම් අටවගන්න පුලුවන්:)
     

    DJvodka

    Well-known member
  • Mar 31, 2009
    3,375
    292
    83
    A land like no other
    VARCHAR තමයි මචෝ තියෙන්නේ. :dull:

    • user කෙනෙක් create කරන තැනයි
    • Login form එකෙයි
    password එක compare කරන්න ඕන code එක යන්තන් කියන්න පුලුවන්ද
    අනිත් ටික නම් අටවගන්න පුලුවන්:)

    save karana thena meka wenas karala balanna.

    Code:
    db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+new String(txtupass.getPassword())+"')");
     

    Voltage

    Well-known member
  • Feb 6, 2012
    21,723
    1
    15,120
    113
    save karana thena meka wenas karala balanna.

    Code:
    db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+new String(txtupass.getPassword())+"')");

    එහෙම කලාම මෙන්න මේ 4 වෙනි ID එකේ තියෙන විදියට save උනේ මචන් :sorry:

    25g9un6.png


    අනිත් ID වල තියෙන විදියට password save වෙනවා මේ යටින් තියෙන විදියට දැම්මම. ඒත් ඒක ආයෙ user ව log කරන තැනද compare කරගන්න ගියාම අවුල් වෙනවනෙ :(

    Code:
    db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+txtupass.getPassword()+"')");


    ------------

    මේ තියේනනේ මගේ user table එක

    dpvdsi.png
     
    Last edited:

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,860
    1
    9,621
    113
    Gampaha
    database එකේ password එකට යන data type එක VARCHAR වලට දැම්මොත් නම් ඔය code එක වැඩ කරනවා. ඒත් plain text තියන එක අවුල් නිසා එකට මොකද්ද මචන්ලා කරන්න ඕන. database එකේ password එක තියන්න හොද මොන data type එකෙන්ද :sorry:
    දැන් තියෙන ඩේටා ටයිප් එක මොකද්ද?
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,860
    1
    9,621
    113
    Gampaha
    එහෙම කලාම මෙන්න මේ 4 වෙනි ID එකේ තියෙන විදියට save උනේ මචන් :sorry:

    25g9un6.png


    අනිත් ID වල තියෙන විදියට password save වෙනවා මේ යටින් තියෙන විදියට දැම්මම. ඒත් ඒක ආයෙ user ව log කරන තැනද compare කරගන්න ගියාම අවුල් වෙනවනෙ :(

    Code:
    db.setData("INSERT INTO users VALUES('"+txtuid.getText()+"','"+userName+"','"+userType+"','"+txtupass.getPassword()+"')");
    ------------

    මේ තියේනනේ මගේ user table එක

    dpvdsi.png
    user id එකක් අවශ්‍ය නොවේ. user name එක unique නිසා ඒක තමයි primary key එක වෙන්නෙ.

    login code එක මෙහෙම දාන්න.


    Code:
    String uname = txtUserName.getText();        
                     
    ResultSet userset = db.getData("Select * from users where user_name='"+uname+"' and user_pw='"+txtPassword.getPassword()+"'");
        if(userset.next()) {
                  
        dispose();
        new mainUI().setVisible(true);
    }
     

    Voltage

    Well-known member
  • Feb 6, 2012
    21,723
    1
    15,120
    113
    user id එකක් අවශ්‍ය නොවේ. user name එක unique නිසා ඒක තමයි primary key එක වෙන්නෙ.

    login code එක මෙහෙම දාන්න.


    Code:
    String uname = txtUserName.getText();        
                     
    ResultSet userset = db.getData("Select * from users where user_name='"+uname+"' and user_pw='"+txtPassword.getPassword()+"'");
        if(userset.next()) {
                  
        dispose();
        new mainUI().setVisible(true);
    }


    password එක db එකේ char එකක් විදියට වෙන වෙන අකුරු වලින් ලස්සනට save වෙනවා
    මට මේක ආයෙ login window එකේදි compare කරන්න ගියාම තමයි පශ්නෙ මතුවෙන්නේ :baffled: :sorry:


    තව පොඩි දෙයක් තියෙනව මචෝ
    උදාහරණයක් විදියට කිවුවොත් දැන් මගේ program එකේ තියෙනවනේ user windows, item windows, invoice windows සහ තව එක එක main windows විිදියට. මං මේ එක එක windows හැදුවෙ එක එක packages ඇතුලට වෙන්න. මං එහෙම හැදුවෙ එතකොට ඒ ඒ files manage කරන්න ලේසි නිසා. එහෙම කලාට මේක exe කරන්න යනකොට අවුලක් එයිද බන්. මං තාම program එකක් exe කරල නැහැ
     
    Last edited: