2012-12-09 175 views
-3

我有一個Java應用程序的問題,我請求你的幫助。我需要開發一個代碼,其中根據提供的約束創建圖表。這必須使用java中的BufferedImage的概念來完成。我已經在c:中存儲了一個圖像,但是無論我畫的是什麼,它都可能是一個簡單的線條或圓圈等,在圖像空間中不會顯示任何圖像。 我還有一個疑問,即可以使用相同的結果集來存儲來自不同表格的數據。我無法解決出現的錯誤。 我的代碼如下:Java應用程序問題

package diagram; 

import diagram.AB; 
import java.awt.*; 
import java.awt.image.*; 
import java.util.*; 
import java.sql.*; 
import java.io.*; 
import javax.swing.*; 
import java.sql.Timestamp; 
import javax.imageio.ImageIO; 

public class AB1 extends JPanel 
{ 
public static void main(String a[]) throws Exception 
{ 
    int ID,TC; 
    String FROM, TO, ATS, DTS, SOURCE, DSTN, TS, ST; 
    ResultSet rs; 

    ArrayList<AB> ab = new ArrayList<AB>(); 

    //DATABASE CONNECTION 

    String TrainNo = "12740"; 
    try 
    { 
    Class.forName("oracle.jdbc.driver.OracleDriver"); 
    String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe"; 
    Connection c = DriverManager.getConnection(url, "system", "akankshadas"); 

    // STORING TABLE IN RESULTSET 

    int rows = 0; 

    PreparedStatement st=c.prepareStatement("select * from MT_TRAIN_CONSIST where TRAIN_NUMBER = ? ORDER BY SERIAL_NUMBER"); 
    rs=st.executeQuery(); 

    PreparedStatement st1=c.prepareStatement("select * from MT_RAKE_TRAIN_LINK_MASTER where TRAIN_NUMBER = ? ORDER BY SERIAL_NUMBER"); 
    rs = st1.executeQuery(); 

    PreparedStatement st2=c.prepareStatement("select * from MT_SLIP_TRAIN_INFO where TRAIN_NUMBER = ? ORDER BY SERIAL_NUMBER "); 
    rs = st2.executeQuery(); 

    while(rs.next()) 
    { 

    ID = rs.getInt("ID_TRAIN_DEF"); 
    FROM = rs.getString("COACH_FROM"); 
    TO = rs.getString("COACH_TO"); 
    TC = rs.getInt("NUMBER_OF_COACHES"); 
    ATS = rs.getString("ATTACH_TRANSFER_STATION"); 
    DTS = rs.getString("DETACH_TRANSFER_STATION"); 
    SOURCE = rs.getString("TRAIN_SRC"); 
    DSTN = rs.getString("TRAIN_DSTN"); 
    TS = rs.getString("TRANSFER_STATION"); 
    ST = rs.getString("slip_type"); 

    AB obj = new AB(); 

    obj.id = ID; 
    obj.tc = TC; 
    obj.from = FROM; 
    obj.to = TO; 
    obj.ats = ATS; 
    obj.dts = DTS; 
    obj.src = SOURCE; 
    obj.dstn = DSTN; 
    obj.ts = TS; 
    obj.st = ST; 
    ab.add(obj); 

    rows++; 
    } 
} 

catch(Exception ex) 
{ 
    ex.printStackTrace(); 
} 

getImg(new FileOutputStream("C:\\A&B" + TrainNo + ".jpg"), ab); 
} 

public static void getImg(OutputStream out, ArrayList<AB> ab) throws IOException 
{ 
int imgWidth = 1024, imgHeight = 768; 

BufferedImage image = new BufferedImage(imgWidth,imgHeight, BufferedImage.TYPE_INT_ARGB); 
Graphics2D gx = image.createGraphics(); 
gx.setColor(Color.BLUE); 

gx.setColor(Color.BLACK); 
gx.drawLine(60,350,970,350); 
} 
} 

它的對象類是

package diagram; 

import java.awt.*; 
import java.awt.image.*; 
import java.awt.event.*; 
import java.util.*; 
import java.sql.*; 
import java.io.*; 
import javax.swing.*; 
import java.sql.Timestamp; 
import java.text.SimpleDateFormat; 
import javax.imageio.ImageIO; 

public class AB 
{ 
public String from, to, ats, dts, src, dstn, ts, st; 
public int id, tc; 

public static void main(String a[]) throws Exception 
{ 
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); 

OutputStream out = new FileOutputStream("C:\\myImg.jpg"); 

ImageIO.write(image, "PNG", out); 
out.close(); 
} 

} 

的錯誤是

java.sql.SQLException: ORA-00904: "SERIAL_NUMBER": invalid identifier 

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) 
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289) 
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573) 
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891) 
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:830) 
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2391) 
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2672) 
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589) 
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:527) 
at diagram.AB1.main(AB1.java:39) 

我很感激所有幫助。我很久以來一直堅持這一點。 三江源

+3

StackOverflow不是在這裏調試你的代碼。請針對具體問題提出問題_。 –

回答

0

錯誤:

java.sql.SQLException: ORA-00904: "SERIAL_NUMBER": invalid identifier 
... 
at diagram.AB1.main(AB1.java:39) 

行:

PreparedStatement st1=c.prepareStatement("select * from MT_RAKE_TRAIN_LINK_MASTER where TRAIN_NUMBER = ? ORDER BY SERIAL_NUMBER"); 

哪些列在表(MT_RAKE_TRAIN_LINK_MASTER)?它是否有SERIAL_NUMBER列?

+0

不,它沒有序列號列....它有一個主要的id_train_def列。每列火車都有一個唯一的號碼,稱爲id_train_def –

+0

這就是爲什麼你會收到錯誤。您正在嘗試通過不存在的SERIAL_NUMBER來排序數據。 – mcalex

+0

哦,是的,謝謝你..刪除它,但仍然代碼不工作 –

0

在這裏您正在使用準備好的聲明。

PreparedStatement st=c.prepareStatement("select * from 
MT_TRAIN_CONSIST where TRAIN_NUMBER = ? ORDER BY SERIAL_NUMBER"); 

st.setInt(1, 100);//enter your train number 

rs=st.executeQuery(); 

在執行PreparedStatement對象之前,您必須提供值代替問號佔位符(如果有的話)。

+0

String TrainNo =「12740」;這個字符串通過代替問號。在這種情況下,值12740通過 –