using a database to upload items

using a database to upload items

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
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
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
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
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
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 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
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 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
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
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>
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 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
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 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
form based file upload using servlets
form based file upload using servlets  Hai all, I wrote a program to upload a file into specified directory and store the file path and username into database. for that i created a html page having browse option and text box i
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
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
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
How to upload file using JSP?
How to upload file using JSP?   Hi all, I m the beginner in JSP, I want to upload file on server in specific folder.   1)page.jsp... file upload form to the user</TITLE></HEAD> <
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 file using FTP in java
how to upload file using FTP in java  hai, i want to upload file using FTP in java Webservices.. Tel me some Articles Regards Asha
Export data in excel sheet via Browse and upload button into mysql database
Export data in excel sheet via Browse and upload button into mysql database  how to create a Browse & Upload Buttons and then save the information from it in mysql database's Table Am using struts2,hibernate for making
database entry using jdbc
database entry using jdbc  Give me a program to enter records in table using jdbc in java.   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Insert data into database Thanks
Android using database
Android using database  How to Add,delete,modify the contact name,address,phone no into the database using android coding
inserting multiple file formats into database using html
inserting multiple file formats into database using html   hi the code was working fine,i want to choose the file and then upload to database,by using html.whether it is possible to upload larger file size,please explain
using database - Development process
using database  i want to ask f we developed off line application then which database will be best for those application
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
how to store image upload path to mssql database
how to store image upload path to mssql database  hi there!!, i need help in storing the image upload path into the database. basically i just use file select to upload the image from jsp to database. however when i click submit
Excel File data upload into postgresql database in struts 1.x
Excel File data upload into postgresql database in struts 1.x  Dear members please explain how Excel Files data upload into postgresql database in struts 1.x
upload file to server and store recode in database
upload file to server and store recode in database  i want to upload a file into the server and store a recode in mysql database.any one know the code
upload a file and write it in JSP using servlet
upload a file and write it in JSP using servlet  Hello, I'm facing a problem here. I want to upload a file through abc.jsp and write the contents of file using a servlet in xyz.jsp. It is supposed to be a excel file which
To Upload and insert the CSV file into Database
To Upload and insert the CSV file into Database... to upload a CSV file through JSP and insert it into the database. For this, we have... on upload_page.jsp. Before proceeding further, we need table in database. We created
database connectivity using mysql
database connectivity using mysql  java file: eg1.java package eg; import java.sql.*; public class eg1 { public static void main(String arg... seconds) I am using Netbeans 5.5, mysql server 5.0, to get data from table
Upload Exce Data into MySql Using Jsp and Servlet - JSP-Servlet
Upload Exce Data into MySql Using Jsp and Servlet  now i am doing... into Mysql Database table so please give the coding to me, it's very urgent for me... the following link: http://www.roseindia.net/jsp/upload-insert-csv.shtml Hope
Accessing Database using EJB
Accessing Database using EJB       This is a simple EJB Application that access the database. Just go... Database. Creating a simple Database driven application in EJB 1)Create

Ads