katada Mata JDBC kiya denna puluwan podi dewal ekak oni query database insert query update query
kasuwa1235 Well-known member Dec 17, 2007 6,353 91 48 gampaha Sep 8, 2015 #1 katada Mata JDBC kiya denna puluwan podi dewal ekak oni query database insert query update query
Ritash9001 Well-known member Sep 29, 2010 1,718 411 83 somewhere is univers Sep 8, 2015 #2 google karapan ona tharam thiyanewa
kasuwa1235 Well-known member Dec 17, 2007 6,353 91 48 gampaha Sep 8, 2015 #3 Ritash9001 said: google karapan ona tharam thiyanewa Click to expand... Man baluwa machan eth mata terenne na
Ritash9001 said: google karapan ona tharam thiyanewa Click to expand... Man baluwa machan eth mata terenne na
manarrow Well-known member Jan 31, 2015 4,990 5,139 113 Sep 8, 2015 #4 kasuwa1235 said: Man baluwa machan eth mata terenne na Click to expand... me thiyenne mage db class eka.. mekata anuwa thama mama insert, update, search anan manan gahala thiyenne. public class DB { public static Connection c; public static Statement st; public static ResultSet rs = null; public static Connection myConnection() throws Exception { Class.forName("com.mysql.jdbc.Driver"); c = DriverManager.getConnection("jdbc:mysql://localhost:3307/inventory_control_system", "root", "123"); return c; } public static void save(String para) throws Exception, NullPointerException { if (c == null) { myConnection(); } c.createStatement().executeUpdate(para); } public static ResultSet search(String quary) throws Exception, NullPointerException { if (c == null) { myConnection(); } rs = c.createStatement().executeQuery(quary); return rs; } } onna othana ubata oona karana insert update query dekath ekka thawath usefull dewal thiyanawa. meka me mama hadapu small inventory ekaka code ekak. therun aran karpan. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel(); int x = 0; try { for (int i = 0; i < jTable1.getRowCount(); i++) { String pid = jTable1.getValueAt(i, 0).toString(); String p_name = jTable1.getValueAt(i, 1).toString(); String quantity = jTable1.getValueAt(i, 2).toString(); String unit_price = jTable1.getValueAt(i, 3).toString(); String sub_total = jTable1.getValueAt(i, 4).toString(); DB.save("insert into invoice (Customer_Customer_ID, Product_Name, Unit_Price, Quntity, Discount, Net_Total, Cash, Balance, Date, Time) values " + "('"+txt_CustomerID.getText()+"', '"+p_name+"', '"+unit_price+"', '"+quantity+"', '"+txt_discount.getText()+"', '"+txt_netTotal.getText()+"', '"+txt_cash.getText()+"', '"+txt_balance.getText()+"', '"+Date.getText()+"', '"+Time.getText()+"')"); DB.search("select Invoice_ID from invoice where Invoice_ID='"+jTextField3.getText()+"'"); if(DB.rs.next()){ x = Integer.parseInt(DB.rs.getString("Invoice_ID").toString()); } DB.save("insert into invoice_registry (Invoice_Invoice_ID, Stock_Product_ID, Product_Name, Unit_Price, Quantity, Total, Cash, Balance, Date, Time) values " + "('"+x+"', '"+pid+"', '"+p_name+"', '"+unit_price+"', '"+quantity+"', '"+sub_total+"', '"+txt_cash.getText()+"', '"+txt_balance.getText()+"', '"+Date.getText()+"', '"+Time.getText()+"')"); DB.save("update stock set quantity=quantity-'"+quantity+"' where Product_ID ='"+pid+"'"); } } catch (Exception e) { e.printStackTrace(); } JOptionPane.showMessageDialog(rootPane, "INVOICE HAS SAVED!"); dtm.setRowCount(0); clearText(); Customer_Name.setText(""); txt_CustomerID.setText(""); }
kasuwa1235 said: Man baluwa machan eth mata terenne na Click to expand... me thiyenne mage db class eka.. mekata anuwa thama mama insert, update, search anan manan gahala thiyenne. public class DB { public static Connection c; public static Statement st; public static ResultSet rs = null; public static Connection myConnection() throws Exception { Class.forName("com.mysql.jdbc.Driver"); c = DriverManager.getConnection("jdbc:mysql://localhost:3307/inventory_control_system", "root", "123"); return c; } public static void save(String para) throws Exception, NullPointerException { if (c == null) { myConnection(); } c.createStatement().executeUpdate(para); } public static ResultSet search(String quary) throws Exception, NullPointerException { if (c == null) { myConnection(); } rs = c.createStatement().executeQuery(quary); return rs; } } onna othana ubata oona karana insert update query dekath ekka thawath usefull dewal thiyanawa. meka me mama hadapu small inventory ekaka code ekak. therun aran karpan. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel(); int x = 0; try { for (int i = 0; i < jTable1.getRowCount(); i++) { String pid = jTable1.getValueAt(i, 0).toString(); String p_name = jTable1.getValueAt(i, 1).toString(); String quantity = jTable1.getValueAt(i, 2).toString(); String unit_price = jTable1.getValueAt(i, 3).toString(); String sub_total = jTable1.getValueAt(i, 4).toString(); DB.save("insert into invoice (Customer_Customer_ID, Product_Name, Unit_Price, Quntity, Discount, Net_Total, Cash, Balance, Date, Time) values " + "('"+txt_CustomerID.getText()+"', '"+p_name+"', '"+unit_price+"', '"+quantity+"', '"+txt_discount.getText()+"', '"+txt_netTotal.getText()+"', '"+txt_cash.getText()+"', '"+txt_balance.getText()+"', '"+Date.getText()+"', '"+Time.getText()+"')"); DB.search("select Invoice_ID from invoice where Invoice_ID='"+jTextField3.getText()+"'"); if(DB.rs.next()){ x = Integer.parseInt(DB.rs.getString("Invoice_ID").toString()); } DB.save("insert into invoice_registry (Invoice_Invoice_ID, Stock_Product_ID, Product_Name, Unit_Price, Quantity, Total, Cash, Balance, Date, Time) values " + "('"+x+"', '"+pid+"', '"+p_name+"', '"+unit_price+"', '"+quantity+"', '"+sub_total+"', '"+txt_cash.getText()+"', '"+txt_balance.getText()+"', '"+Date.getText()+"', '"+Time.getText()+"')"); DB.save("update stock set quantity=quantity-'"+quantity+"' where Product_ID ='"+pid+"'"); } } catch (Exception e) { e.printStackTrace(); } JOptionPane.showMessageDialog(rootPane, "INVOICE HAS SAVED!"); dtm.setRowCount(0); clearText(); Customer_Name.setText(""); txt_CustomerID.setText(""); }
KingCM Well-known member Jul 23, 2013 6,920 948 113 www.biogen.lk Sep 8, 2015 #5 mihicherub ge thread ekak thibba.... poddak eka balanna....