Package java.sql

Examples of java.sql.Statement


      throw new IOException(sqle.getMessage());
    }

    try {
      // Creating a statement lets us issue commands against the connection.
      Statement s = conn.createStatement();
      // We create the table.
//         s.execute("create cached table JoramDB(name VARCHAR PRIMARY KEY, content VARBINARY(256))");
      /*
      s.execute("CREATE TABLE JoramDB (name VARCHAR(256), content LONG VARCHAR FOR BIT DATA, PRIMARY KEY(name))");
      */
      s.execute("CREATE TABLE JoramDB (name VARCHAR(256), content longblob, primary key(name))"); // MySQL
      s.close();
      conn.commit();
    } catch (SQLException sqle) {
        String exceptionString = sqle.toString();
        if (exceptionString.indexOf("CREATE command denied") == -1)
        {
View Full Code Here


   * @return The list of corresponding names.
   */
  public String[] list(String prefix) throws IOException {
    try {
      // Creating a statement lets us issue commands against the connection.
      Statement s = conn.createStatement();
      ResultSet rs = s.executeQuery("SELECT name FROM JoramDB WHERE name LIKE '" + prefix + "%'");

      Vector v = new Vector();
      while (rs.next()) {
        v.add(rs.getString(1));
      }
      rs.close();
      s.close();

      String[] result = new String[v.size()];
      result = (String[]) v.toArray(result);

      return result;
View Full Code Here

      fname = new StringBuffer(dirName).append('/').append(name).toString();
    }

    try {
      // Creating a statement lets us issue commands against the connection.
      Statement s = conn.createStatement();
      //
      ResultSet rs = s.executeQuery("SELECT content FROM JoramDB WHERE name='" + fname + "'");

       if (!rs.next()) {
         throw new FileNotFoundException("Cannot find object in JoramDB " + ("serverCounter".equals(fname)?"[KNOWN PROBLEM] ":"") + fname);
       }

       byte[] content = rs.getBytes(1);

       rs.close();
       s.close();

       if (logger.isLoggable(BasicLevel.DEBUG))
           logger.log(BasicLevel.DEBUG, "load, after database call");

       nbloaded += 1;
View Full Code Here

    }

    int nb = 0;
    try {
      // Creating a statement lets us issue commands against the connection.
      Statement s = conn.createStatement();
      //
      nb = s.executeUpdate("DELETE FROM JoramDB WHERE name='" + fname + "'");
    } catch (SQLException sqle) {
      if (sqle instanceof com.mysql.jdbc.CommunicationsException && !reconnectLoop)
      {
          logger.log(BasicLevel.WARN, "Database reconnection problem at delete, Reconnecting");
          reconnection();
View Full Code Here

    private void testCachingResults() throws SQLException {
        org.h2.Driver.load();
        Connection ca = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
        Connection cb = DriverManager.getConnection("jdbc:h2:mem:two", "sa", "sa");

        Statement sa = ca.createStatement();
        Statement sb = cb.createStatement();
        sa.execute("CREATE TABLE TEST(ID VARCHAR)");
        sa.execute("INSERT INTO TEST (ID) VALUES('abc')");
        sb.execute("CREATE LOCAL TEMPORARY LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')");

        PreparedStatement paData = ca.prepareStatement("select id from TEST where id = ?");
        PreparedStatement pbData = cb.prepareStatement("select id from T where id = ?");
        PreparedStatement paCount = ca.prepareStatement("select count(*) from TEST");
        PreparedStatement pbCount = cb.prepareStatement("select count(*) from T");
View Full Code Here

        deleteDb("testLinkedTableInReadOnlyDb");
        org.h2.Driver.load();

        Connection memConn = DriverManager.getConnection("jdbc:h2:mem:one", "sa", "sa");
        Statement memStat = memConn.createStatement();
        memStat.execute("CREATE TABLE TEST(ID VARCHAR)");

        String url1 = getURL("testLinkedTableInReadOnlyDb", true);
        Connection conn = DriverManager.getConnection(url1, "sa1", "abc abc");
        Statement stat = conn.createStatement();
        stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
        conn.close();

        String[] files = IOUtils.listFiles(getBaseDir());
        for (String file : files) {
            String name = IOUtils.getFileName(file);
            if ((name.startsWith("testLinkedTableInReadOnlyDb")) && (!name.endsWith(".trace.db"))) {
                FileSystem.getInstance(file).setReadOnly(file);
                boolean isReadOnly = FileSystem.getInstance(file).isReadOnly(file);
                if (!isReadOnly) {
                    fail("File " + file + " is not read only. Can't test it.");
                }
            }
        }

        // Now it's read only
        conn = DriverManager.getConnection(url1, "sa1", "abc abc");
        stat = conn.createStatement();
        stat.execute("CREATE LOCAL TEMPORARY LINKED TABLE T(NULL, 'jdbc:h2:mem:one', 'sa', 'sa', 'TEST')");
        // This is valid because it's a linked table
        stat.execute("INSERT INTO T VALUES('abc')");

        conn.close();
        memConn.close();

        deleteDb("testLinkedTableInReadOnlyDb");
View Full Code Here

   */
  public int update(String query) throws SQLException {
    if (!isConnected())
      throw new IllegalStateException("Not connected, please connect first!");
   
    Statement statement;
    if (!isCursorScrollable())
      statement = m_Connection.createStatement(
    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    else
      statement = m_Connection.createStatement(
    getSupportedCursorScrollType(), ResultSet.CONCUR_READ_ONLY);
    int result = statement.executeUpdate(query);
    statement.close();
   
    return result;
  }
View Full Code Here

   */
  public ResultSet select(String query) throws SQLException {
    if (!isConnected())
      throw new IllegalStateException("Not connected, please connect first!");
   
    Statement statement;
    if (!isCursorScrollable())
      statement = m_Connection.createStatement(
    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    else
      statement = m_Connection.createStatement(
    getSupportedCursorScrollType(), ResultSet.CONCUR_READ_ONLY);
    ResultSet result = statement.executeQuery(query);
   
    return result;
  }
View Full Code Here

   *
   * @param rs    the ResultSet to clean up
   */
  public void close(ResultSet rs) {
    try {
      Statement statement = rs.getStatement();
      rs.close();
      statement.close();
      statement = null;
      rs = null;
    }
    catch (Exception e) {
      // ignored
View Full Code Here

    */
   private void stopStandaloneDatabase() throws Exception
   {
       try
       {
           final Statement stmt = connection.createStatement() ;
           stmt.execute("shutdown") ;
       }
       finally
       {
           connection = null;
       }
View Full Code Here

TOP

Related Classes of java.sql.Statement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.