Need to pass information from MS access database to another prog
Hi,
I really need some help here...
I need to pass selected information from my database to another information.
I am able to select and display the infotmation but i am not sure how i can transfer the information to the next program. Can any one please offer me some assistance?
My code is as follow:
/* Getting data from PSM32 and displaying it *can work* */
import java.net.URL;
import java.sql.*;
import java.lang.String;
/** Application to create a Ganttchart * */
publicclass PSMdb
{
publicstaticvoid main (String argv[])
{
//SQLQueryFormat a = new SQLQueryFormat();
System.out.println("\nEstablishing Connection - Pls Wait... \n");
/** Get Info fr database**/
try
{
//Connect to the database specified in the URL
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:PSM32");
System.out.println("Connection Established.\n");
//Create a SELECT statement object
Statement statmt = con.createStatement();
//Issue the SELECT statement
String querySt ="SELECT Set, Name, Order " +
"FROM PMETERS " +
"WHERE Set = 'BRAKE.BAK' ";
//Create and execute query
ResultSet res = statmt.executeQuery(querySt);
while (res.next())
{
String Proj = res.getString(1);//get Proj Name
String Task = res.getString(2);//get Task Name
//Print statement
System.out.println("" +Proj);
System.out.println("" +Task);
}
//Close Statement and Connection
statmt.close();
con.close();
System.out.println("\nConnection Closed - Operation Successful.");
}
catch(Exception E)
{
//Print out the Exception Error
System.out.println("Error:" +E );
}
}
}
And yes there is another problem. I can compile and run the program in a C:\folder but when i open the document in a project workspace, i cant compile the above code. Can any one please offer me assistance?
Thanks a million.
[3428 byte] By [
Aristala] at [2007-11-26 14:51:44]

To NanookOITheNorth:
> Could you provide some more relevent information
> about what the other program is and how data should
> be transferred to it? API? Socket? File?
was wanted to use the "return task" thing. Issit possible to use that?
To annie79:
my next program is supposed to retrive the events in the "task" field and display it in a applet. After retriving the tasks i will be getting the dates to produce the gantt chart. uses the jfree lib functions.
the code for the applet is as follow
/* original gantt chart program that can work*/
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.Date;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.category.IntervalCategoryDataset;
import org.jfree.data.gantt.Task;
import org.jfree.data.gantt.TaskSeries;
import org.jfree.data.gantt.TaskSeriesCollection;
import org.jfree.data.time.SimpleTimePeriod;
/** Application to create a Ganttchart * */
public class Ganttchart extends JApplet{
/** @param title , frame title **/
public void init() {
final IntervalCategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
// add the chart to a panel...
final ChartPanel chartPanel = new ChartPanel(chart);
// this size (500, 270) here doesn't matter cos this become the html control
// how big u wan can change in the html code the width="800" height="600"
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
/**
* Creates a sample dataset for a Ganttchart.
*
* @return The dataset.
*/
public static IntervalCategoryDataset createDataset() {
//"Task" information should be retrived from the database to replace this current 1
/*final TaskSeries s1 = new TaskSeries("Scheduled");
s1.add(new Task("Write Proposal",
new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
date(5, Calendar.APRIL, 2001))));
s1.add(new Task("Obtain Approval",
new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
date(9, Calendar.APRIL, 2001))));
s1.add(new Task("Requirements Analysis",
new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
date(5, Calendar.MAY, 2001))));
final TaskSeries s2 = new TaskSeries("Actual");
s2.add(new Task("Write Proposal",
new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
date(5, Calendar.APRIL, 2001))));
s2.add(new Task("Obtain Approval",
new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
date(9, Calendar.APRIL, 2001))));
s2.add(new Task("Requirements Analysis",
new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
date(15, Calendar.MAY, 2001))));*/
final TaskSeriesCollection collection = new TaskSeriesCollection();
collection.add(s1);
collection.add(s2);
return collection;
}
/**
* Utility method for creating <code>Date</code> objects.
*
* @param day the date.
* @param month the month.
* @param year the year.
*
* @return a date.
*/
private static Date date(final int day, final int month, final int year) {
final Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day);
final Date result = calendar.getTime();
return result;
}
/**
* Creates a chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private JFreeChart createChart(final IntervalCategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createGanttChart(
"Ganttchart", // chart title
"Task", // domain axis label
"Date", // range axis label
dataset, // data
true,// include legend
true,// tooltips
false// urls
);
//chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
return chart;
}
}
As for the "run the program in a C:\folder but when i open the
> document in a project workspace, i cant compile the
> above code. Can any one please offer me assistance?"
The run time error that i get is "java.lang.NoSuchMethodError: main
Exception in thread "main" "
Please give me some leads on how i can cont to proceed?
Thanks a lot