Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jdbc:sqlite不重新修改数据_Java_Sqlite_Sqlitejdbc - Fatal编程技术网

Java jdbc:sqlite不重新修改数据

Java jdbc:sqlite不重新修改数据,java,sqlite,sqlitejdbc,Java,Sqlite,Sqlitejdbc,我使用jdbc:sqlite访问sqlite数据库,并通过简单的select语句获取一些记录。数据库中有行,但java函数不返回任何内容 private static String ConnectionString = "jdbc:sqlite:D:\\My Documents\\NetBeansProjects\\IntelligentBusStop\\BusSystem.db"; private static ResultSet GetData(String command) {

我使用jdbc:sqlite访问sqlite数据库,并通过简单的select语句获取一些记录。数据库中有行,但java函数不返回任何内容

   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 ;
    }
}
private static String ConnectionString=“jdbc:sqlite:D:\\mydocuments\\NetBeansProjects\\IntelligentBusStop\\BusSystem.db”;
私有静态结果集GetData(字符串命令)
{
连接=空;
Statement=null;
ResultSet ResultSet=null;
尝试
{
Class.forName(“org.sqlite.JDBC”);
connection=DriverManager.getConnection(ConnectionString);
statement=connection.createStatement();
resultSet=statement.executeQuery(命令);
返回结果集;
}
捕获(例外e)
{
e、 printStackTrace();
返回null;
}
最后
{
尝试
{
resultSet.close();
语句。close();
connection.close();
}
捕获(例外e)
{
e、 printStackTrace();
}
}
}
公共静态数组列表GetStopBS()
{
ResultSet results=GetData(“从StopTable中选择StopNumber、标记、纬度、经度”);
ArrayList停止=新建ArrayList();
尝试
{
while(results.next())
{
StopBS newStop=新StopBS();
newStop.StopNumber=results.getInt(“StopNumber”);
newStop.Tag=results.getString(“Tag”);
newStop.Lat=results.getFloat(“纬度”);
newStop.Long=results.getFloat(“经度”);
停止。添加(newStop);
}
返回站;
}
捕获(例外e)
{
e、 printStackTrace();
返回null;
}
}

直接在数据库上使用sql语句是有效的。我正在使用RazorSQL查看数据库,如果这有什么不同的话

GetData
中关闭
ResultSet
,因此当
GetStopBS
尝试将其加载到数据结构中时,光标不可用

我会重写这段代码来正确地完成它。你很接近,但不在那里

学习Sun编码标准。您遵循的是.NET标准,而不是Java

当你关闭你的语句、结果集和连接时,你的心是在正确的地方,但我不同意你把代码放在哪里。我建议永远不要将java.sql包引用传递到创建它们的方法范围之外。使用相同的方法创建、使用和关闭它们


您还应该在finally块中关闭它们,将close包装在单个try/catch块中。

while循环多少次?放进一个system.out.println什么的