Home Answers Viewqa Java-Beginners using a database to upload items

 
 


Jaja
using a database to upload items
3 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners

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 Pages:
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
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 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
UPLOAD  how to upload image using html
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
upload video
upload video  hi sir i want to code of upload and download video in mysql database using jsp... and plz give advice which data type is used to store video in table
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 pdf
upload pdf   i want to dispal content of pdf fil and stored into database in human readable form using php . how can i do
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
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
image upload
be upload in the server and their path should be stored in database either... to database The given code allow the user to browse and upload selected file...image upload  Hello sir I want to upload image or any other type
Imge upload
Imge upload  how to upload image in jsp.I am using Glassfish server..   Here is a code that upload an image on tomcat server and save it to database. 1)page.jsp: <%@ page language="java" %> <HTML> <
image upload
image upload  How to access image file from database using jsp?   retrieveimage.jsp: <%@page import="java.sql.*,java.io.*"%> <% try{ InputStream sImage; Class.forName("com.mysql.jdbc.Driver
display ten items
display ten items  Sir ,in my shopping project when i do search it displays all items according to search criteria from database , i want display only ten items at a time and give next as link to disply remaining items. please
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
upload and download mp3
upload and download mp3   code of upload and download Mp3 file in mysql database using jsp and plz mention which data type used to store mp3 file in mysql database
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
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
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc and txt)which has to be store in database and also retrieve the file from database
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
Multiple file upload - Struts
Multiple file upload  HI all, I m trying to upload multiple files using struts and jsp. I m using enctype="multipart". and the number of files need to upload is dynamically generated. I have tried using formfile. and also
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
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 Photo to Server
Upload Photo to Server  Hi I am using NetBeans IDE for developing application for java(Swings). And i am using MySQL as backend database. My Problem is I have created JFrame form in NetBeans and i have inculded label in which
Photo upload, Download
Photo upload, Download  Hi I am using NetBeans IDE for developing application for java(Swings). And i am using MySQL as backend database. My Problem is I have created JFrame form in NetBeans and i have inculded label in which i
Upload Image using Servlet
Upload Image using Servlet       This application illustrates how to upload an image using servlet... of the image into database. Finally the uploaded image is displayed
shoping items billng source code
shoping items billng source code  Hi, I am doing a project on invoice...", here in this page i need to get the items from the data base with respect... should be sorted by the most selected items order, I want to add two or more items
shoping items billng source code
shoping items billng source code  Hi, I am doing a project on invoice...", here in this page i need to get the items from the data base with respect... should be sorted by the most selected items order, I want to add two or more items
shoping items billng source code
shoping items billng source code  Hi, I am doing a project on invoice...", here in this page i need to get the items from the data base with respect... should be sorted by the most selected items order, I want to add two or more items
shoping items billng source code
shoping items billng source code  Hi, I am doing a project on invoice...", here in this page i need to get the items from the data base with respect... should be sorted by the most selected items order, I want to add two or more items
shoping items billng source code
shoping items billng source code  Hi, I am doing a project on invoice...", here in this page i need to get the items from the data base with respect... should be sorted by the most selected items order, I want to add two or more items
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
To Upload and insert the file into Database with Current Date and Time In JSP
To Upload and insert the file  into Database with Current Date... into database with current date and time using JDBC database.  This can be done... into database having used pstatement=con.prepareStatement(queryString); (iii). Using
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 and display image and text records using JSP and Oracle
Upload and display image and text records using JSP and Oracle  Hi all, I'm using JSP and Oracle 10g. I could retrieve and display records from database. But i couldnot retrieve and display image. I want to store
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
file upload using spring - Spring
file upload using spring  How to upload a file in server using spring framework
upload an image
upload an image  Hello, i would like to upload an image to the database. how can i do it? what field type should i set in the database? thanx
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>
How to browse and upload the file in same page using jsp.
How to browse and upload the file in same page using jsp.  Hi, I am doing a project and i want to browse and upload the file in same page inside.... Regards, Santhosh.   Here is a jsp upload file application. The given code
How to browse and upload the file in same page using jsp.
How to browse and upload the file in same page using jsp.  Hi Sir, I am doing a project in jsp servlets and i want to browse and upload... in advance. Regards, Santhosh   Here is a jsp upload file application
File Upload
File Upload  when i execute the image upload to mysql database it shows an exception that file path cannot be found
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
HTML Upload
HTML Upload  Hi, I want to upload a word / excel document using the html code (web interface)need to get displayed on another webpage. Please let me the coding to display on another webpage using

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.