Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
Java JDBC
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="manarrow" data-source="post: 18934705" data-attributes="member: 524640"><p><span style="font-size: 18px"><span style="color: Blue">me thiyenne mage db class eka.. mekata anuwa thama mama insert, update, search anan manan gahala thiyenne.</span></span></p><p></p><p><span style="font-size: 12px"><span style="color: Red">public class DB {</span></span></p><p><span style="font-size: 12px"><span style="color: Red"></span></span></p><p><span style="font-size: 12px"><span style="color: Red"> public static Connection c;</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> public static Statement st;</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> public static ResultSet rs = null;</span></span></p><p><span style="font-size: 12px"><span style="color: Red"></span></span></p><p><span style="font-size: 12px"><span style="color: Red"> public static Connection myConnection() throws Exception {</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> Class.forName("com.mysql.jdbc.Driver");</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> c = DriverManager.getConnection("jdbc:mysql://localhost:3307/inventory_control_system", "root", "123");</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> return c;</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> }</span></span></p><p><span style="font-size: 12px"><span style="color: Red"></span></span></p><p><span style="font-size: 12px"><span style="color: Red"> public static void save(String para) throws Exception, NullPointerException {</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> if (c == null) {</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> myConnection();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> }</span></span></p><p><span style="font-size: 12px"><span style="color: Red"></span></span></p><p><span style="font-size: 12px"><span style="color: Red"> c.createStatement().executeUpdate(para);</span></span></p><p><span style="font-size: 12px"><span style="color: Red"></span></span></p><p><span style="font-size: 12px"><span style="color: Red"> }</span></span></p><p><span style="font-size: 12px"><span style="color: Red"></span></span></p><p><span style="font-size: 12px"><span style="color: Red"> public static ResultSet search(String quary) throws Exception, NullPointerException {</span></span></p><p><span style="font-size: 12px"><span style="color: Red"></span></span></p><p><span style="font-size: 12px"><span style="color: Red"> if (c == null) {</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> myConnection();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> }</span></span></p><p><span style="font-size: 12px"><span style="color: Red"></span></span></p><p><span style="font-size: 12px"><span style="color: Red"> rs = c.createStatement().executeQuery(quary);</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> return rs;</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> }</span></span></p><p><span style="font-size: 12px"><span style="color: Red">}</span></span></p><p></p><p><span style="font-size: 18px"><span style="color: Blue">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.</span></span></p><p><span style="font-size: 18px"><span style="color: Blue"></span></span></p><p></p><p> <span style="font-size: 12px"><span style="color: Red">private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { </span></span></p><p><span style="font-size: 12px"><span style="color: Red"> DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> int x = 0;</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> try {</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> for (int i = 0; i < jTable1.getRowCount(); i++) {</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> String pid = jTable1.getValueAt(i, 0).toString();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> String p_name = jTable1.getValueAt(i, 1).toString();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> String quantity = jTable1.getValueAt(i, 2).toString();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> String unit_price = jTable1.getValueAt(i, 3).toString();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> String sub_total = jTable1.getValueAt(i, 4).toString();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> </span></span></p><p><span style="font-size: 12px"><span style="color: Red"> DB.save("insert into invoice (Customer_Customer_ID, Product_Name, Unit_Price, Quntity, Discount, Net_Total, Cash, Balance, Date, Time) values "</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> + "('"+txt_CustomerID.getText()+"', '"+p_name+"', '"+unit_price+"', '"+quantity+"', '"+txt_discount.getText()+"', '"+txt_netTotal.getText()+"', '"+txt_cash.getText()+"', '"+txt_balance.getText()+"', '"+Date.getText()+"', '"+Time.getText()+"')");</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> </span></span></p><p><span style="font-size: 12px"><span style="color: Red"> DB.search("select Invoice_ID from invoice where Invoice_ID='"+jTextField3.getText()+"'");</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> if(DB.rs.next()){</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> x = Integer.parseInt(DB.rs.getString("Invoice_ID").toString());</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> }</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> </span></span></p><p><span style="font-size: 12px"><span style="color: Red"> DB.save("insert into invoice_registry (Invoice_Invoice_ID, Stock_Product_ID, Product_Name, Unit_Price, Quantity, Total, Cash, Balance, Date, Time) values "</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> + "('"+x+"', '"+pid+"', '"+p_name+"', '"+unit_price+"', '"+quantity+"', '"+sub_total+"', '"+txt_cash.getText()+"', '"+txt_balance.getText()+"', '"+Date.getText()+"', '"+Time.getText()+"')");</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> </span></span></p><p><span style="font-size: 12px"><span style="color: Red"> DB.save("update stock set quantity=quantity-'"+quantity+"' where Product_ID ='"+pid+"'");</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> }</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> </span></span></p><p><span style="font-size: 12px"><span style="color: Red"> } catch (Exception e) {</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> e.printStackTrace();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> }</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> JOptionPane.showMessageDialog(rootPane, "INVOICE HAS SAVED!");</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> dtm.setRowCount(0);</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> clearText();</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> Customer_Name.setText("");</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> txt_CustomerID.setText("");</span></span></p><p><span style="font-size: 12px"><span style="color: Red"> }</span></span></p></blockquote><p></p>
[QUOTE="manarrow, post: 18934705, member: 524640"] [SIZE="5"][COLOR="Blue"]me thiyenne mage db class eka.. mekata anuwa thama mama insert, update, search anan manan gahala thiyenne.[/COLOR][/SIZE] [SIZE="3"][COLOR="Red"]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; } }[/COLOR][/SIZE] [SIZE="5"][COLOR="Blue"]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. [/COLOR][/SIZE] [SIZE="3"][COLOR="Red"]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(""); }[/COLOR][/SIZE] [/QUOTE]
Insert quotes…
Verification
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom