SearchBean:
package pbc;
import java.sql.*;
import java.util.ArrayList;
public class SearchBean {
private String strSql,companyName,address,tel1 = null;
public ArrayList openDb() {
ArrayList arrlist = null;
String strSql = "select top 10 * from speed.dbo.tblcompany";
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String connectionUrl = "jdbc:microsoft:sqlserver://localhost;database=speed;user=sa;password=123456";
Connection conn = DriverManager.getConnection(connectionUrl);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(strSql);
while (rs.next()) {
arrlist.add(rs.getString("companyname"));
}
conn.close();
}
catch(Exception ex){
System.out.println(ex);
System.exit(0);
}
return arrlist;
}
}
调用此Bean的ActionForm
ArrayList arrlist = searchdata.openDb();
然后这一句出错了,出错的消息为:java.lang.NullPointerException
请问为什么?