1 Reply Latest reply on May 4, 2014 7:13 PM by rp0428

    Jdbc SqlException

    nye'e

      Hi,

      I get an Sqlexecption with this message "com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set."

      when i execute this query

      ...

      Statement stmt = conn.createStatement();

      stmt.executeUpdate("IF EXISTS (SELECT name FROM master.sys.databases WHERE name = N'Repository')\n"

                      + "PRINT 'Database exists'\n"

                      + "ELSE\n"

                      + "BEGIN\n"

                      + " PRINT 'Database does not exists'\n"

                      + " create database Repository\n"

                      + "END");

      or this statement

       

      Statement stmt = conn.createStatement();

      stmt.executeQuery("IF  NOT EXISTS "

                      + "("

                      + "   SELECT [name] FROM sys.tables \n"

                      + "   WHERE [name] = 'Employee'"

                      + ")\n"

                      + "CREATE TABLE [Employee]\n"

                      + "(\n"

                      + "    [First Name] varchar(10),"

                      + "    [Last Name] varchar(10),"

                      + "    Phone int"

                      + ")");

       

      I want to create a database and a table in sql server if it doesn't exist

      pls how can i prevent this error;

        • 1. Re: Jdbc SqlException
          rp0428
          I get an Sqlexecption with this message "com.microsoft.sqlserver.jdbc.SQLServerException: The statement did not return a result set."

           

          So naturally the FIRST question you ask yourself was: Does my statement return a result set?

           

          The answer to that question will tell you ONE of your problems.

          I want to create a database and a table in sql server if it doesn't exist

          You can't combine DML with DDL and you can't combine queries with SQL code.

           

          1. execute a DML query to test if the objects exist.

          2. in Java examine the result set from that query

          3. if the objects do NOT exist then execute a DDL statement to create them.