| | |
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2009
Posts: 1
Reputation:
Solved Threads: 0
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
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
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.
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.
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver (Java)
- facing problem in database connectivity in java to mysql (Java)
- JDBC Connection with MySQL problem "Ubuntu 7.10" (Java)
- ClassNotFoundException with MySql and Netbeans (Java)
- Prroblem during Connecting Servlet with JDBC (Community Introductions)
- Problem to connect Servlet and JDBC (MySQL)
- facing problem in database connectivity in jsp to mysql (JSP)
Other Threads in the Java Forum
- Previous Thread: The e.getSource() method from ActionEvent e in a listener
- Next Thread: How to mock protected method in Java
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component csv database desktop draw ebook eclipse equation error event exception fractal game givemetehcodez graphics gui html ide image input integer intersect iphone j2me java java.xls javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions reporting rotatetext scanner screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream






