so how can we do it?
part of code that access database is as follows
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.io.*;
import java.util.*;
public class Price extends JFrame
{
String productname;
int itemprice=0;
int quantity;
int price=0;
int tpp[]= new int[2];// changed vector to int array.
Price(String str3,int s)
{
productname = str3;
quantity=s;
}
public int[] priceCal()throws Exception{
System.out.println("---------at first line of price calc-------");
Class.forName("com.mysql.jdbc.Driver");
System.out.println("--------1--------");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/sudha","root","infistech");
System.out.println("--------2--------");
// Read data from a table
Statement st = con.createStatement();
System.out.println("--------3--------");
ResultSet rs=st.executeQuery("select productname,price from shop where productname='"+productname+"'");
System.out.println("--------4--------");
rs.next();
System.out.println("--------5--------");
String str=rs.getString("productname");
if(str.equals(productname))
{
System.out.println("--------6--------");
itemprice=rs.getInt("price");
price=quantity*itemprice;
tpp[0]=price;
tpp[1]=itemprice;
System.out.println("---price of the item--"+tpp[0]);
con.close();
return tpp;
}
else // if product name not found in the database set the values to zero
{
System.out.println("--------7--------");
price=0;
itemprice=0;
tpp[0]=price;
tpp[1]=itemprice;
System.out.println("---price of the item--"+tpp[0]);
con.close();
return tpp;
}
}//end of totPriceCal method
}// end of class Price
*Edited to add the [ code] tags and make this code readable without scrolling 10 times the screen
in the future please
This post has been edited by pbl: 07 December 2008 - 09:36 PM

New Topic/Question
Reply




MultiQuote





|