swing aplication execution which access database

for to execute the swing application where i have to put mysql-connect

Page 1 of 1

13 Replies - 3532 Views - Last Post: 11 December 2008 - 03:36 AM Rate Topic: -----

#1 svdsudhakar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-December 08

swing aplication execution which access database

Post icon  Posted 06 December 2008 - 05:16 AM

]for to execute the swing application where i have to put mysql-connector-java-5.1.5-bin.jar file. i successfully compiled the program but while i started execution it is showing that class not found exception com.mysql.jdbc.Driver. from that we can understand that mysql-connector-java-5.1.5-bin.jar file is not recognised.

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 :code:

This post has been edited by pbl: 07 December 2008 - 09:36 PM


Is This A Good Question/Topic? 0
  • +

Replies To: swing aplication execution which access database

#2 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: swing aplication execution which access database

Posted 06 December 2008 - 06:41 AM

Please use the edit button to correct your post.
:code:

Have a read here
http://java.sun.com/...view/index.html

This post has been edited by janotte: 06 December 2008 - 06:44 AM

Was This Post Helpful? 0
  • +
  • -

#3 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2687
  • View blog
  • Posts: 11,349
  • Joined: 20-September 08

Re: swing aplication execution which access database

Posted 06 December 2008 - 02:46 PM

You need to ensure that driver jar is in your classpath
Was This Post Helpful? 0
  • +
  • -

#4 svdsudhakar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-December 08

Re: swing aplication execution which access database

Posted 07 December 2008 - 09:22 PM

View Postg00se, on 6 Dec, 2008 - 01:46 PM, said:

You need to ensure that driver jar is in your classpath


hi friend thanks for your reply. and my problem is i set the classpath and compiled successfully and then only i am running. if CLASSPATH is not set then the program will not compile. so my program is successfully compiled means the driver jar file is in CLASS PATH. and my stand alone file which access database is working fine whic means jar file is in CLASSPATH.

THE PROBLEM IS FROM SWING APPLICATION ONLY IT WONT WORKING. THAT IS MY PROBLEM. PLEASE HELP ME IN THIS REGARD.

SUDHAAKAR.
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2687
  • View blog
  • Posts: 11,349
  • Joined: 20-September 08

Re: swing aplication execution which access database

Posted 08 December 2008 - 03:22 AM

Quote

so my program is successfully compiled means the driver jar file is in CLASS PATH.


No. The driver class is loaded dynamically so javac won't care if the driver is not even on your system.

Post the result of placing the following as the first line of your main method:

System.out.println(System.getProperty("java.class.path"));


Was This Post Helpful? 0
  • +
  • -

#6 svdsudhakar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-December 08

Re: swing aplication execution which access database

Posted 08 December 2008 - 04:37 AM

hi friend,
ok i agree with your suggestion and i checked the CLASSPATH using System property and it is showing the jar file, mysql-connector-java-5.1.5-bin.jar.

and one more thing if i run the same code using stand alone application it is working fine, means a class which contains main method.

now MY PROBLEM IS WHEN I START EXECUTING THE SAME FROM SWING APPLICATION IT IS NOT RECOGNISING THE CLASS com.mysql.jdbc.Driver. this is the problem.

it is working from a class which contains the main method and not working from a swing aplication.

this is the problem friend.

SO I NEED YOUR KIND ATTENTION AND HELP IN THIS REGARD.
Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2687
  • View blog
  • Posts: 11,349
  • Joined: 20-September 08

Re: swing aplication execution which access database

Posted 08 December 2008 - 05:05 AM

Quote

Post the result of placing the following as the first line of your main method:

Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: swing aplication execution which access database

Posted 08 December 2008 - 07:26 PM

View Postsvdsudhakar, on 6 Dec, 2008 - 04:16 AM, said:



Do you have the same imports in your Swing version ?

One thing for sure, you have a ";" missing at the end of this SQL statement
   ResultSet rs=st.executeQuery("select productname,price from shop where productname='"+productname+"'");


Was This Post Helpful? 0
  • +
  • -

#9 svdsudhakar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-December 08

Re: swing aplication execution which access database

Posted 08 December 2008 - 10:45 PM

View Postg00se, on 8 Dec, 2008 - 04:05 AM, said:

Quote

Post the result of placing the following as the first line of your main method:

hi,

i didnt understand what you said, but i solved the problem by
placing the mysql-connector-java-5.1.5-bin.jar file in jre/lib/ext folder and
jre/lib folders.

and i f remove the mysql-connector-java-5.1.5-bin.jar file from these two folders it is not working. as it is jre environment it is identifying the jar file.
it is now workling fine and any application can run if we place our jar files what are they, here in the two folders of jre.

i dont understand, why swing application is not working if the jar file is in the CLASSPATH also.

thanks for your adivces.
Was This Post Helpful? 0
  • +
  • -

#10 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2687
  • View blog
  • Posts: 11,349
  • Joined: 20-September 08

Re: swing aplication execution which access database

Posted 09 December 2008 - 01:48 AM

Quote

i dont understand, why swing application is not working if the jar file is in the CLASSPATH also.


It ISN'T in the classpath. You've just put it there though, by putting the jar in the ext directory
Was This Post Helpful? 0
  • +
  • -

#11 svdsudhakar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-December 08

Re: swing aplication execution which access database

Posted 09 December 2008 - 02:12 AM

View Postg00se, on 9 Dec, 2008 - 12:48 AM, said:

Quote

i dont understand, why swing application is not working if the jar file is in the CLASSPATH also.


It ISN'T in the classpath. You've just put it there though, by putting the jar in the ext directory


hi,

what i said is that my swing application working fine if i placed the mysql-connector-java-5.1.5-bin.jar file in jre/lib and jre/lib/ext folders.

and if i remove mysql-connector-java-5.1.5-bin.jar file from these two folders my swing application is not running even if mysql-connector-java-5.1.5-bin.jar is in the CLASSPATH also.

the same thing repetead in my friends system also with this swing application.

my question is why it is not recognising the jar file which i placed in the CLASSPATH.

if CLASSPATH is not set properly then my other applications wont work which access database. but they are working fine from being as stand alone applications. the problem is it is not working from my other swing applications also. this is my problem.

thanks for your replies,
sudhakar.

This post has been edited by svdsudhakar: 09 December 2008 - 02:16 AM

Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: swing aplication execution which access database

Posted 09 December 2008 - 06:51 PM

Really weird...
can you post the code of your console application
Was This Post Helpful? 0
  • +
  • -

#13 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2687
  • View blog
  • Posts: 11,349
  • Joined: 20-September 08

Re: swing aplication execution which access database

Posted 10 December 2008 - 01:51 AM

Quote

my question is why it is not recognising the jar file which i placed in the CLASSPATH.


Because it wasn't in the classpath. If you'd followed my suggestion above, beginning:

Quote

Post the result of placing the following as the first line of your main method:


that would have become clear. If you want to do that now,

a. take the driver jar of your ext directory
b. confirm that's broken it by running the app
c. follow my original suggestion
Was This Post Helpful? 0
  • +
  • -

#14 svdsudhakar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-December 08

Re: swing aplication execution which access database

Posted 11 December 2008 - 03:36 AM

ok and i got it.
thanks for your assistance to me...

sudhakar.

This post has been edited by svdsudhakar: 11 December 2008 - 03:37 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1