すべての値がテーブルに格納されたデータベースがあります。drawString() メソッドを使用してテーブルから名前を出力したい。結果セットと配列リストを作成しました。drawString メソッドでデータベースから文字列を渡す方法はありますか??
私はこれが初めてなので、コードまたはコードへのリンクを提供してください..ありがとう.
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 = "287972";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@127.0.0.1:1521:xe";
Connection c = DriverManager.getConnection(url, "system", "mypcdatabase");
// STORING TABLE IN RESULTSET
int rows = 0;
PreparedStatement st=c.prepareStatement("select * from MT_TRAIN_CONSIST where TRAIN_NUMBER = ?" );
rs=st.executeQuery();
PreparedStatement st1=c.prepareStatement("select * from MT_RAKE_TRAIN_LINK_MASTER where TRAIN_NUMBER = ?");
rs = st1.executeQuery();
PreparedStatement st2=c.prepareStatement("select * from MT_SLIP_TRAIN_INFO where TRAIN_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);
gx.drawLine(970,350,960,340);
gx.drawLine(970, 350, 960, 360);
gx.drawString("", 30 , 330);
gx.drawString("", 960 , 330);
ImageIO.write(image, "PNG", out);
out.close();
}
}