java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 1
Reputation: nabeelanwer is an unknown quantity at this point 
Solved Threads: 0
nabeelanwer nabeelanwer is offline Offline
Newbie Poster

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

 
0
  #1
Jun 11th, 2009
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.lang.*;
import javax.swing.JApplet;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
//import org.jfree.chart.demo.Time;


/**
* A simple demonstration application showing how to create a line chart using data from a
* {@link CategoryDataset}.
*/
public class LineChartDemo1 extends JApplet{

private Connection con = null;

@Override
public void init(){


// Connection con = null;

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();


}catch(ClassNotFoundException e)
{

System.out.println(e);
}catch(InstantiationException e)
{
System.out.println(e);
}catch(IllegalAccessException e)
{
System.out.println(e);
}

final CategoryDataset dataset = createDataset() ;
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
//setContentPane(chartPanel);

chartPanel.setPopupMenu(null);
//add the chartPanel to the container (getContentPane is inherited from JApplet which AppletGraph extends).
Container content = getContentPane();
content.add(chartPanel);

//JFreeChart jFreeChart = generateGraph();

//Put the jFreeChart in a chartPanel
//ChartPanel chartPanel = new ChartPanel(jFreeChart);
//chartPanel.setPreferredSize(new Dimension(900,600));






}//end of init method


// public LineChartDemo1() {
// //super("Line Chart");
// final CategoryDataset dataset = createDataset() ;
// final JFreeChart chart = createChart(dataset);
// final ChartPanel chartPanel = new ChartPanel(chart);
// chartPanel.setPreferredSize(new Dimension(500, 270));
// setContentPane(chartPanel);
// }




private CategoryDataset createDataset() {

// row keys...
final String series1 = "First";
final String series2 = "Second";
final String series3 = "Third";

// column keys...
final String type1 = "1";
final String type2 = "2";
final String type3 = "3";
final String type4 = "4";
final String type5 = "5";
final String type6 = "6";
final String type7 = "7";
final String type8 = "8";
final String type9 = "9";

// create the dataset...
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

//Connection con = null;
try {
// Class.forName("com.mysql.jdbc.Driver").newInstance();

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/XCORE","root","helloworld");
Statement stmt = con.createStatement();
ResultSet rslt = stmt.executeQuery("SELECT SUM(ACTIVE) FROM STATISTICS WHERE");

//Time time = new Time();
System.currentTimeMillis();

// Date date= new Date();


//date = time.getLocalDateTime((System.currentTimeMillis())*1000);
//date.setMinutes(5);



while(rslt.next()){
for(int i = 0;i < 10; i++)
{
dataset.addValue(rslt.getInt(1), series1, String.valueOf(i));

}
}

rslt.close();
if(!con.isClosed())
System.out.println("Successfully connected to " + "MySQL server using TCP/IP...");

} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}


return dataset;

}

private JFreeChart createChart(final CategoryDataset dataset) {

// create the chart...
final JFreeChart chart = ChartFactory.createLineChart(
"Xipx Statistics Graph", // chart title
"Time ", // domain axis label
"Calls ", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);


chart.setBackgroundPaint(Color.white);

final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);

// customise the range axis...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);



// customise the renderer...
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
// renderer.setDrawShapes(true);

renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,1.0f, new float[] {10.0f, 6.0f}, 0.0f));
renderer.setSeriesStroke(
1, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {6.0f, 6.0f}, 0.0f
)
);
renderer.setSeriesStroke(
2, new BasicStroke(
2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
1.0f, new float[] {2.0f, 6.0f}, 0.0f
)
);
// OPTIONAL CUSTOMISATION COMPLETED.

return chart;
}


}
_________________________________________________
Classpath has been set ... but the applet is still not working
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 494
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

 
0
  #2
Jun 11th, 2009
Welcome nabeelanwer.

Read this http://www.daniweb.com/forums/announcement9-3.html.

Your java code must be surrounded with bb code tags.

You cannot perform sql operation with an applet. If you want to do so then you have to work with java policy & security manager system.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,241
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 490
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

 
-1
  #3
Jun 11th, 2009
I never attempted this, neither I had opportunity and interest to work with applets but according to Sun tutorials it is possible to do it. Just have look at this example that is "nicked" fro Sun
Last edited by peter_budo; Jun 11th, 2009 at 7:28 am.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC