不同类别的方法1:
public train[] search_train()
{
int i=1;
try
{
String sql="select * from train ";
rs=st.executeQuery(sql);
while(rs.next()){
t[i]= new train();
t[i].train_id=rs.getInt("TRAIN_ID");
i++;
}
}
catch(Exception e)
{
e.printStackTrace();
}
return t;
}
方法2(获取对象数组):
train t[]= new train[20];
t=d.search();
System.out.print(t[2].no);`
打印空值。
答案 0 :(得分:0)
根据评论,解决方案是修复数组索引。
我想补充一点,Java命名约定更喜欢大写的对象名称。 <!DOCTYPE html>
<html>
<head>
<title>Test page</title>
</head>
<body>
<h1>Test page</h1>
<p>
Testing</p>
<p>Testing
Testing</p>
<p>Testing
Testing
Testing</p>
<p>Testing
Testing
Testing
Testing</p>
<p>
<a href="#">Testing</a>
</p>
<p><a href="#">Testing</a>
<a href="#">Testing</a></p>
<p><a href="#">Testing</a>
<a href="#">Testing</a>
<a href="#">Testing</a></p>
<p><a href="#">Testing</a>
<a href="#">Testing</a>
<a href="#">Testing</a>
<a href="#">Testing</a></p>
<p><a href="#">Testing</a>
Testing</p>
<p><a href="#">Testing</a>
<a href="#">Testing</a>
Testing</p>
<p><a href="#">Testing</a>
<a href="#">Testing</a>
<a href="#">Testing</a>
Testing</p>
<p><a href="#">Testing</a>
<a href="#">Testing</a>
<a href="#">Testing</a>
<a href="#">Testing</a>
Testing</p>
<p><a href="#">Testing</a>
<a href="#">Testing</a>
<a href="#">Testing</a>
<a href="#">Testing</a>
Testing
Testing</p>
</body>
</html>
- &gt;在这种情况下,train
和CamelCase方法名称,或Train
。虽然,看起来这个方法应该被称为searchTrain
,因为在这个代码块中没有搜索。
getTrains