1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
/*
* This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
* project.
*
* Copyright (C) 1998-2009 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
package testsuite;
// test for bug #2308
import java.sql.*;
import java.io.*;
import java.util.Properties;
import java.sql.ResultSetMetaData;
public class TestScrollPrepare {
public static void main (String[] args)
{
try
{
String driver = "virtuoso.jdbc4.Driver";
Class.forName( driver );
String url;
if(args.length == 0)
url = "jdbc:virtuoso://localhost:1111";
else
url = args[0];
System.out.println("--------------------- Test of scrollable prepareStatement -------------------");
System.out.println ("URL - " + url);
Connection con = DriverManager.getConnection(url, "dba", "dba");
System.out.println ("@JBDC connection established through " + driver);
System.out.print("Create a preparedStatement scrollable class");
// if I use the following prepared statement, the query executes, results
// are obtained, but virtuoso crashes when the "stmt.close()" executes.
PreparedStatement stmt = con.prepareStatement("select * from sys_users",
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
// if I use the following prepared statement, everything works fine
//PreparedStatement stmt = con.prepareStatement("select * from s_group");
ResultSet resultSet = stmt.executeQuery();
ResultSetMetaData rsmd = resultSet.getMetaData();
int numCols = rsmd.getColumnCount() ;
for (int i = 1 ; i <= numCols ; i++)
{
String colName = rsmd.getColumnName(i) ;
System.out.println(" .. colName = " + colName);
}
while (resultSet.next())
{
String primaryKey = resultSet.getString(1);
System.out.println ("primary key :"+primaryKey) ;
}
resultSet.close();
System.out.println("@ResultSet closed");
stmt.close();
System.out.println("@Statement closed");
con.close();
System.out.println(" PASSED");
}
catch (Exception e)
{
System.out.println(" FAILED");
e.printStackTrace();
System.exit(-1);
}
}
}
|