Jaja
using a database to upload items
3 Answer(s)      6 years and 7 months ago
Posted in : Java Beginners
Advertisement
View Answers

December 15, 2009 at 1:02 PM


Hi Friend,

Try the following code:

import javax.swing.*;
import java.awt.*;
import java.text.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;

class SalesTax extends JFrame {
double tax=0.10;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11;
JTextField text;
JButton b1,b2,b3;
JPanel panel;
JTextArea area;
JScrollPane pane;
public SalesTax(){
panel=new JPanel(new GridLayout(8,2));
text=new JTextField(20);
l1=new JLabel("Enter Item Code:");
l2=new JLabel("Item Name: ");
l3=new JLabel();
l4=new JLabel("Item Price: ");
l5=new JLabel();
l6=new JLabel("Item Code: ");
l7=new JLabel();
l8=new JLabel("Tax: ");
l9=new JLabel();
l10=new JLabel("Total Price: ");
l11=new JLabel();
b1=new JButton("Submit");
b2=new JButton("Total");
b3=new JButton("Display All Items On Console");
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int co=Integer.parseInt(text.getText());
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from item where Item_Code='"+co+"'");
String name="";
double p=0.0;
while (rs.next())
{
name=rs.getString("Item_Name");
p=rs.getDouble("Item_Price");
}
l3.setText(name);
l5.setText(Double.toString(p));
l7.setText(text.getText());
}
catch(Exception ex){}
l2.setVisible(true);
l3.setVisible(true);
l4.setVisible(true);
l5.setVisible(true);
l6.setVisible(true);
l7.setVisible(true);
b2.setVisible(true);
l1.setVisible(false);
text.setVisible(false);
b1.setVisible(false);
b3.setVisible(false);
}
});


December 15, 2009 at 1:04 PM


continue....

b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String st=l5.getText();
double pr=Double.parseDouble(st);
//imposing tax of 10% on each item
double taxprice=pr*tax;
double tprice=pr+taxprice;
l9.setText(Double.toString(taxprice));
l11.setText(Double.toString(tprice));

l2.setVisible(true);
l3.setVisible(true);
l4.setVisible(true);
l5.setVisible(true);
l6.setVisible(true);
l7.setVisible(true);
l8.setVisible(true);
l9.setVisible(true);
l10.setVisible(true);
l11.setVisible(true);
b3.setVisible(true);
b2.setVisible(false);
l1.setVisible(false);
text.setVisible(false);
b1.setVisible(false);
}
});
b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register";, "root", "root");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from item");
String strVal="";
ResultSetMetaData md=rs.getMetaData();
int col= md.getColumnCount();
for (int i=0; i<col; i++) {
System.out.print(md.getColumnName(i+1)+" ");
}
System.out.println();
while(rs.next()){
for (int i=0; i<col; i++){
System.out.print(rs.getString(i+1)+" ");
}
System.out.println();
}
}
catch(Exception ex){}
}
});
l2.setVisible(false);
l3.setVisible(false);
l4.setVisible(false);
l5.setVisible(false);
l6.setVisible(false);
l7.setVisible(false);
b2.setVisible(false);
b3.setVisible(false);
l8.setVisible(false);
l9.setVisible(false);
l10.setVisible(false);
l11.setVisible(false);

panel.add(l6);
panel.add(l7);
panel.add(l2);
panel.add(l3);
panel.add(l4);
panel.add(l5);
panel.add(l8);
panel.add(l9);
panel.add(l10);
panel.add(l11);
panel.add(l1);
panel.add(text);
panel.add(b1);
panel.add(b2);
panel.add(b3);
add(panel);
setVisible(true);
pack();
}
}
public class PosGUI{
public static void main(String []args){
SalesTax tax=new SalesTax();
}
}

Hope that the above code will be helpful for you.
Thanks


December 15, 2009 at 1:18 PM


Hi Friend,

Create table 'item' in the database:

CREATE TABLE `item` (
`Item_Code` bigint(20) default NULL,
`Item_Name` varchar(40) default NULL,
`Item_Price` double default NULL
)

Thanks









Related Tutorials/Questions & Answers:
using a database to upload items - Java Beginners
using a database to upload items  I need to create a database to upload item codes so that when i input the item code is displays on the screen. here is my code and the items i need in a database import javax.swing.*; import
Image upload in mysql database using jsp servlet
Image upload in mysql database using jsp servlet  Hello, I need code to insert image in mysql database, I have seen the code which is already in your portal but it is not inserting image into database it save in the folder
Advertisements
Unable to upload a file to mysql database using struts1
Unable to upload a file to mysql database using struts1  Hi, Below..." %> <html:html> <body> <html:form action="upload" enctype...("Connection Opened."); PreparedStatement pst=con.prepareStatement("insert into upload
insert name city and upload image in database using mysql and jsp
insert name city and upload image in database using mysql and jsp   insert name city and upload image in database using mysql and jsp
Read code from excel sheet and upload into database using JSP
Read code from excel sheet and upload into database using JSP  I want to upload data to database from an excel worksheet using jsp ...Please help
dyanamic upload of images using struts without database connection
dyanamic upload of images using struts without database connection  I want to upload images dynamically with out using data base..and want to create image for every user in my db
Upload Excel into Database Table Using SERVLET - JSP-Servlet
Upload Excel into Database Table Using SERVLET  Hi i hava sitution that upload .xls file into database table which has same coloumn names... in database table are NAME,ID,SAL. please help me to upload that excel using
upload file and insert other details to database using a single form
upload file and insert other details to database using a single form   hi.. I have problem with uploading a file and insert other user datas together which I retrieved from another jsp/html page. Here i was able to upload file
How i upload file and save that record in database using JSP?
How i upload file and save that record in database using JSP?  Hi All, I m the beginner in JSP and I want to upload the file and store that file and some other form data in MySQL database. Ex. There is one employee detail form
How I Upload File and Store that file name in Database using JSP
How I Upload File and Store that file name in Database using JSP  Hi All, I m the beginner in JSP and I want to upload the file and store that file and some other form data in MySQL database. Ex. There is one employee detail
How to Upload a file directly to Oracle database using JSP or Servlets?
How to Upload a file directly to Oracle database using JSP or Servlets?  Hi I want to upload a file(csv or excel) to Oracle 10g Database using JSP...;Upload File to Oracle Database</h2> <form id="form1" enctype
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my...; <table> <tr><TD ><B>Upload Image</B><...;<TD ><B>Upload Image</B></TD> <td><input type
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my...; <table> <tr><TD ><B>Upload Image</B><...;TD ><B>Upload Image</B></TD> <td><input type="file
upload image to database
upload image to database  i am try to upload image to MySql database using netbeans. when jsp execute it return no error. but also data does inserted in database. i am using blob datatype and preopared statement
how to upload an image from a jsp page to a mysql database table using jsp
how to upload an image from a jsp page to a mysql database table using jsp  how to upload an image from a jsp page to a mysql database table using jspstrong text
upload to database - JSP-Servlet
upload to database  hai friends i have a query that is i have to upload a pdf file into database(sqlserver2000) using jsp. In roseindia some examples... into database whenever i want that uploaded pdf file i have to retrieve
upload video using php
upload video using php  How to upload a video on MYSQL Server using PHP Code..? Can any one provide me an example
Add Items in JComboBox from Access Database - Java Beginners
Add Items in JComboBox from Access Database  Heelo Sir I want To add ittem in JComboBox which is stored in Access Database. plz Help Me Sir Database Column name -Course Items -MBA,MCA,MBA IT,MBA FINANCE I want Load Database
Upload csv or .xlsx file from JSP form to Database Table using servlet
Upload csv or .xlsx file from JSP form to Database Table using servlet ... and stores it into the oracle database table. Sir Its very Urgent I have to Submit My Project i am using following code which is Working for .xls Excel file
upload image using JSP Hibernate
upload image using JSP Hibernate  sir, I want to take image from user and save to database(MYSQL) using Hibernate and JSP Thanks in advance
file upload using spring - Spring
file upload using spring  How to upload a file in server using spring framework
file upload using JSP
file upload using JSP  I have created a form to upload a file...="java" %> <HTML> <HEAD><TITLE>Display file upload form...;center> <td colspan="2" align="center"><B>UPLOAD THE FILE</B>
upload csv to mysql db using jsp upload
upload csv to mysql db using jsp upload  Hello all, Please give me the code to uplad .csv from jsp page and insert values into MySQl db. I have a table with 8 cloumns.(MDN--varchar(30),Otafdate date,crt varchar(30),dmdn
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
upload using youtube api - MobileApplications
upload using youtube api   sir, as u have asked for my question i m sending it again plz reply me.i want code for java based mobile application, that can take .3GP video file and upload it to youtube using youtube's APIs
file upload and insert name into database - JSP-Servlet
file upload and insert name into database  Hi, I just joined as a fresher and was given task to upload a file and insert its name into database...  HIread for more information,http://www.roseindia.net/jsp/file_upload
Multiple image upload using JSP
Multiple image upload using JSP  I have written a code to upload the multiple images using jsp, but when I execute this code, it throws Corrupt form...="text/html; charset=utf-8" /> <FORM action="upload_jsp.jsp" enctype
Upload Image to Database through Servlet - JSP-Servlet
Upload Image to Database through Servlet  Hello, I make a application from where I upload the Image from local disk then store in DB.Before storing... isMultipart = FileUpload.isMultipartContent(req); // Create a new file upload
How to upload files to server using JSP/Servlet?
How to upload files to server using JSP/Servlet?  How to upload files to server using JSP/Servlet
how to upload and download images using buttons in jsp?
how to upload and download images using buttons in jsp?  how to upload and download images using buttons in jsp
Advertisement