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]
# 1
>i am not sure how i can transfer the information to the next program.How does "the next program" currently read "the information".
DrLaszloJamfa at 2007-7-8 8:39:57 > top of Java-index,Java Essentials,New To Java...
# 2

> I need to pass selected information from my database

> to another information.

huh!

> 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?

What do you mean by "transfer to next program"? Do you mean you want to pass it to another class? What kind of data do you need to pass and where and why?

> My code is as follow:

*SNIP*

>//Close Statement and Connection

> tatmt.close();

> con.close();

Although this is not related to your question, I feel it necessary to point out that you would face a problem later on for not closing JDBC resources properly. The correct place to close them is in the finally block so that the statements and connections are properly closed even when an exception is generated in the earlier part of the try block.

> 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?

What does can't compile mean? What message do you get while compiling?

annie79a at 2007-7-8 8:39:57 > top of Java-index,Java Essentials,New To Java...
# 3

Hey Cheers for the code example :)

As others have asked, what do you mean "the other program" ? I assume you're talking

about another process running....is that the same system or another system?

You don't have too many options there unless the "other" program has a listener interface

or some sort of API you can tie into using shared memory. Can you configure the "other" program

to read data in from flat files or perhaps xml files?

Thats about all I can think of without more information about the environment.

bruceuka at 2007-7-8 8:39:57 > top of Java-index,Java Essentials,New To Java...
# 4

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

Aristala at 2007-7-8 8:39:57 > top of Java-index,Java Essentials,New To Java...
# 5
erm is there any1 that can help this old folk here whos not getting much progress?thanks a lot
Aristala at 2007-7-8 8:39:57 > top of Java-index,Java Essentials,New To Java...
# 6
> The run time error that i get is "java.lang.NoSuchMethodError: main> Exception in thread "main" "You can't run applets using java.exe. It's an applet, not a stand-alone application.
CeciNEstPasUnProgrammeura at 2007-7-8 8:39:57 > top of Java-index,Java Essentials,New To Java...
# 7
I'm sorry but can u elaborate?
Aristala at 2007-7-8 8:39:57 > top of Java-index,Java Essentials,New To Java...
# 8
> I'm sorry but can u elaborate?Your program is not a program it is an Applet.
cotton.ma at 2007-7-8 8:39:57 > top of Java-index,Java Essentials,New To Java...
# 9
Erm i still havnt got any idea how i can alter the program such that it will be able to retrive tasks from a database to display in the ganttchart.Please help
Aristala at 2007-7-8 8:39:58 > top of Java-index,Java Essentials,New To Java...