我正在使用jdbc:sqlite來訪問sqlite數據庫並通過一個簡單的select語句獲取一些記錄。數據庫中有行,但java函數不返回任何內容。jdbc:sqlite不撤回數據
private static String ConnectionString = "jdbc:sqlite:D:\\My Documents\\NetBeansProjects\\IntelligentBusStop\\BusSystem.db";
private static ResultSet GetData(String command)
{
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try
{
Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection(ConnectionString);
statement = connection.createStatement();
resultSet = statement.executeQuery(command);
return resultSet;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
finally
{
try
{
resultSet.close();
statement.close();
connection.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
public static ArrayList<StopBS> GetStopBS()
{
ResultSet results = GetData("Select StopNumber, Tag, Latitude, Longitude FROM StopTable ");
ArrayList<StopBS> stops = new ArrayList<StopBS>();
try
{
while (results.next())
{
StopBS newStop = new StopBS();
newStop.StopNumber = results.getInt("StopNumber");
newStop.Tag = results.getString("Tag");
newStop.Lat = results.getFloat("Latitude");
newStop.Long = results.getFloat("Longitude");
stops.add(newStop);
}
return stops;
}
catch (Exception e)
{
e.printStackTrace();
return null ;
}
}
直接在數據庫上使用sql語句工作。我正在使用Razor sql查看分貝,如果這有什麼區別。
你的while循環循環了多少次?把一個system.out.println或東西 – 2011-04-27 10:33:58