Home » Developer & Programmer » JDeveloper, Java & XML » Error in connection
Error in connection [message #179940] Thu, 29 June 2006 06:23 Go to next message
ambika
Messages: 1
Registered: June 2006
Junior Member
i am new to java programming.
I wrote a code to generate a jpeg image by taking user inputs.
Now i want to use the same code to connect to database and get values from the database.
I tried to make connection to the database. but im getting the following error

C:\Documents and Settings\ambikakashi_nagaraj\My Documents\FinGraphProducer_try.java:29: <identifier> expected
Class.forName("oracle.jdbc.driver.OracleDriver");
^
1 error

Tool completed with exit code 1



Can anybody help me?

CODE IS AS BELOW

/*
* FinGraphProducer
*/
import java.io.*;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.FontMetrics;


import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

public class FinGraphProducer_try implements ImageProducer
{
private static int ImageWidth = 300;
private static int ImageHeight = 300;

private static int VertInset = 25;
private static int HorzInset = 25;
private static int HatchLength = 10;


Class.forName("oracle.jdbc.driver.OracleDriver");


Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@***********", "****", "****");


/**
* Request the producer create an image
*
* @param stream stream to write image into
* @return image type
*/
public String createImage(OutputStream stream) throws IOException
{



JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(stream);

BufferedImage bi = new BufferedImage(ImageWidth + 10,
ImageHeight,
BufferedImage.TYPE_BYTE_INDEXED);

graphics = bi.createGraphics();
graphics.setColor(Color.white);
graphics.fillRect(0, 0, bi.getWidth(), bi.getHeight());

graphics.setColor(Color.red);

createVerticalAxis();
createHorizontalAxis();



int[] values=readItems();
System.out.println(values.length);
int[] thres_values=readThresholdItems();

plotItems(values,thres_values);


encoder.encode(bi);

return "image/jpg";
}

/**
* Create the vertical axis
*
*
*/
void createVerticalAxis()
{

vertAxis = new Line2D.Double(HorzInset,
VertInset,
HorzInset,
ImageHeight - VertInset);
graphics.draw(vertAxis);


// Draw the vertical hatch marks

}

/**
* Create the horizontal axis
*
*
*/
void createHorizontalAxis()
{
horAxis = new Line2D.Double(HorzInset,
ImageHeight - VertInset,
ImageWidth - HorzInset,
ImageHeight - VertInset);
graphics.draw(horAxis);




}


void decorateHorizontalLine(Graphics2D graphics, Line2D.Double line, String text)
{
double endX = line.getX1();
double endY = line.getY1();
double baseX = endX;
double baseY = endY;

//***************************************************************
// The text should be slightly to the left of the line
// and centered
//***************************************************************
FontMetrics metrics = graphics.getFontMetrics();
baseX -= metrics.stringWidth(text);
baseY += metrics.getAscent()/2;
graphics.drawString(text,
new Float(baseX).floatValue(),
new Float(baseY).floatValue());
}

/**
* Adds decorating text to the enpoint of a vertical line
*
*/
void decorateVerticalLine (Graphics2D graphics, Line2D.Double line, String text)
{
double endX = line.getX2();
double endY = line.getY2();
double baseX = endX;
double baseY = endY;

//***************************************************************
// Center the text over the line
//***************************************************************
FontMetrics metrics = graphics.getFontMetrics();
baseX -= metrics.stringWidth(text)/2;
baseY += metrics.getAscent();

graphics.drawString(text,
new Float(baseX).floatValue(),
new Float(baseY).floatValue());

}

int[] readItems() throws IOException
{
BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) );
String snoTransaction;
int noTransaction=0;
System.out.print( "Enter the Number of transactions: " );


// Read a line of text from the user.
snoTransaction = stdin.readLine();
noTransaction = Integer.parseInt( snoTransaction );

String[] input_Values=new String[noTransaction];

int[] values=new int[noTransaction];

for (int i = 0; i < noTransaction; i++)
{
// Prompt the user
System.out.print( "Type RT of Test"+(i+1)+":" );


// Read a line of text from the user.
input_Values[i] = stdin.readLine();
values[i] = Integer.parseInt( input_Values[i] );

}

return values;

}


int[] readThresholdItems() throws IOException
{
BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) );

String[] threshold_values=new String[3];
int[] thres_values=new int[3];
// Prompt the user
System.out.print( "Type RT of Simple Tran: " );


// Read a line of text from the user.
threshold_values[0] = stdin.readLine();
thres_values[0] = Integer.parseInt( threshold_values[0] );
// Prompt the user
System.out.print( "Type RT of Complex Tran: " );


// Read a line of text from the user.
threshold_values[1] = stdin.readLine();
thres_values[1] = Integer.parseInt( threshold_values[1] );

// Prompt the user
System.out.print( "Type RT of Highly Complex Tran: " );


// Read a line of text from the user.
threshold_values[2] = stdin.readLine();
thres_values[2] = Integer.parseInt( threshold_values[2] );


return thres_values;

}

void plotItems(int[] items,int[] thres_values)
{
//***************************************************************
// calculatePriceRatio will determine the percentage of the
// Y axis the price is, then multiply by the Y axis length.
//
//***************************************************************
int max_graph_value=(thres_values[2]*4)/3;
//graphics.drawLine(HorzInset,(int)(ImageHeight - VertInset-100),ImageWidth-2*HorzInset,(int)(ImageHeight - VertInset-100));
float yscale=(ImageHeight-2*VertInset)/max_graph_value;
int interval=(ImageWidth-2*HorzInset)/(items.length*2);

//graphics.fillRect(HorzInset+10,(int)(ImageHeight - VertInset-(items[0]*yscale)) ,10,(int)((items[0]*yscale)));


for (int i = 0; i < 3; i++)
{
graphics.setColor(Color.lightGray);
graphics.drawLine(HorzInset,(int)(ImageHeight - VertInset-(thres_values[i]*yscale)),(ImageWidth-HorzInset),(int)(ImageHeight - VertInset-(thres_values[i]*yscale)));
}


for(int i = 1; i <= items.length; i++)
{
if (items[i-1]<thres_values[0])
{
graphics.setColor(Color.black);
graphics.drawRect((HorzInset+(interval+(i-1)*2*interval)),(int)(ImageHeight - VertInset-(items[i-1]*yscale)) ,interval,(int)((items[i-1]*yscale)));
graphics.setColor(Color.blue);
graphics.fillRect((HorzInset+(interval+(i-1)*2*interval)),(int)(ImageHeight - VertInset-(items[i-1]*yscale)) ,interval,(int)((items[i-1]*yscale)));
}
else if (items[i-1]<thres_values[1])
{
graphics.setColor(Color.black);
graphics.drawRect((HorzInset+(interval+(i-1)*2*interval)),(int)(ImageHeight - VertInset-(items[i-1]*yscale)) ,interval,(int)((items[i-1]*yscale)));
graphics.setColor(Color.green);
graphics.fillRect((HorzInset+(interval+(i-1)*2*interval)),(int)(ImageHeight - VertInset-(items[i-1]*yscale)) ,interval,(int)((items[i-1]*yscale)));
}
else if (items[i-1]<thres_values[2])
{
graphics.setColor(Color.black);
graphics.drawRect((HorzInset+(interval+(i-1)*2*interval)),(int)(ImageHeight - VertInset-(items[i-1]*yscale)) ,interval,(int)((items[i-1]*yscale)));
graphics.setColor(Color.pink);
graphics.fillRect((HorzInset+(interval+(i-1)*2*interval)),(int)(ImageHeight - VertInset-(items[i-1]*yscale)) ,interval,(int)((items[i-1]*yscale)));
}
else
{
graphics.setColor(Color.black);
graphics.drawRect((HorzInset+(interval+(i-1)*2*interval)),(int)(ImageHeight - VertInset-(items[i-1]*yscale)) ,interval,(int)((items[i-1]*yscale)));
graphics.setColor(Color.red);
graphics.fillRect((HorzInset+(interval+(i-1)*2*interval)),(int)(ImageHeight - VertInset-(items[i-1]*yscale)) ,interval,(int)((items[i-1]*yscale)));
}



//graphics.draw(line1);
//graphics.draw(line2);
//graphics.draw(line3);
//graphics.draw(line4);
}
}


public static void main(String[] args)
{

try
{
FileOutputStream f = new FileOutputStream("graph.jpg");
FinGraphProducer_try producer = new FinGraphProducer_try();
producer.createImage(f);
f.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}

private Line2D.Double vertAxis;
private Line2D.Double horAxis;
private double[] horizontalAxisTicks;
private int highVerticalRange;
private int lowVerticalRange;
private Graphics2D graphics;
private Line2D.Double[] verticalAxisTicks;

private double verticalYTop;
private double verticalYBottom;

}
Re: Error in connection [message #205064 is a reply to message #179940] Thu, 23 November 2006 03:19 Go to previous message
mnrnjn
Messages: 61
Registered: November 2006
Location: india
Member
hi
you must import java.sql.*;

i think now it ill work

byeee
Previous Topic: What is JDeveloper??
Next Topic: new to JDev and Struts - OracleJSP:java.io.FileNotFoundException
Goto Forum:
  


Current Time: Fri Apr 19 13:17:52 CDT 2024