niyomax

Well-known member
  • Sep 24, 2014
    4,595
    7,483
    113
    ........................
    ........................

    ........................

    ........................

    ........................


    මචංලා මේක මගේ යාලුවෙක්ගේ ජාවා ප්‍රොජෙක්ට් එකක්..අසයින්මන්ට් එකකට කරන..මේකේ කමෙන්ට් කරලා තියෙනවා //methana null pointer exception eka කියලා..පොඩ්ඩක් කෝඩ් එක බලලා..අවුල මොකක්ද කියන්න පුලුවන්ද :rolleyes:



    import java.awt.Toolkit;

    import java.sql.Connection;

    import java.sql.PreparedStatement;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.util.logging.Level;

    import java.util.logging.Logger;

    import javax.swing.JOptionPane;

    import net.proteanit.sql.DbUtils; //additional jar file

    /**

    *

    * @author sss

    */

    public class NewSaleDruglist extends javax.swing.JFrame {

    Connection conn = null;

    ResultSet rs = null;

    PreparedStatement pst = null;

    /**

    * Creates new form SaleDruglist

    */

    public NewSaleDruglist() throws SQLException {

    initComponents();

    initialize();//calling method for change java title bar icon

    updateTable();//calling method for updating table from db

    conn = MYSQLConnect.ConnectDB();

    }

    //changing the titile bar java icon

    private void initialize(){

    this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("stock.png")));

    }

    private void updateTable(){

    try {

    String sql = "SELECT * FROM druginfo";

    pst=conn.prepareStatement(sql);//methana null pointer exception eka

    pennanne


    rs=pst.executeQuery();

    table_list.setModel(DbUtils.resultSetToTableModel(rs));

    } catch (Exception ex) {

    JOptionPane.showMessageDialog(null, "Error : "+ex);

    }

    }
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,849
    1
    9,594
    113
    Gampaha
    updateTable();//calling method for updating table from db

    conn = MYSQLConnect.ConnectDB();

    ඔය දෙක මාරු කරන්න. මුලින් connection එක හදල පස්සෙ updateTable method එක call කරන්න.
     
    • Like
    Reactions: EK_SheSH

    niyomax

    Well-known member
  • Sep 24, 2014
    4,595
    7,483
    113
    updateTable();//calling method for updating table from db

    conn = MYSQLConnect.ConnectDB();

    ඔය දෙක මාරු කරන්න. මුලින් connection එක හදල පස්සෙ updateTable method එක call කරන්න.

    Thanx machoo..mama kiyannam ;)