import java.sql.*;
import java.awt.Graphics;
import java.io.Serializable;
public class JdbcDemo{
public JdbcDemo()
{
int id[]=new int[200];
int style[]=new int[200];
Double p1[]=new Double[200];
Double p2[]=new Double[200];
Double p3[]=new Double[200];
Double p4[]=new Double[200];
Double p5[]=new Double[200];
Double p6[]=new Double[200];
int i=0;
String query="SELECT id,style,p1,p2,p3,p4,p5,p6 FROM draw";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =DriverManager.getConnection ("jdbc:odbc:CAXA");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(query);
while (rs.next()){
id[i]=rs.getInt("id");
style[i]=rs.getInt("style");
p1[i]=rs.getDouble("p1");
p2[i]=rs.getDouble("p2");
p3[i]=rs.getDouble("p3");
p4[i]=rs.getDouble("p4");
p5[i]=rs.getDouble("p5");
p6[i]=rs.getDouble("p6");
System.out.println(id[i]+","+style[i]+","+p1[i]+","+p2[i]+","+p3[i]+","+p4[i]+","+p5[i]+","+p6[i]);
i++;
}
con.close();
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
}
System.out.println(i);
}
}
class Execute extends java.applet.Applet implements Serializable
{
public Execute()
{
JdbcDemo x = new JdbcDemo();
}
public void paint(Graphics g)
{
for(int k=0;k<=i;k++)
{
if(style[k]==1)
g.drawLine(p1[k],p2[k],p3[k],p4[k]);
if(style[k]==2)
g.drawOval(p1[k],p2[k],p3[k],p4[k]);
}
}
}
以上是我做一个题的代码,读取数据库的类没有问题但画图的类怎么也找不到 JdbcDemo类中读取的数组,
而且我将 JdbcDemo类已经设为了public,还望指点!