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;

FacebookTwitterLinkedin
Pin It
Joomla Tutorials for Beginners