Results 1 to 4 of 4
  1. #1
    pi4r0n is offline Member
    Join Date
    Jan 2011
    Posts
    19
    Rep Power
    0

    Question sqljdbc4.jar - SQL 2008 - Create database -The statement did not return a result set.

    Hello ALL

    I got a problem when creating a database. When I got to this statment
    statement createDatabase = null;
    createDatabase = con.createStatement();

    ResultSet result = null;
    result = createDatabase.executeQuery("CREATE DATABASE TestDB");
    I got an error
    The statement did not return a result set.
    There is no stac trace but I know its failing on result = createDatabase.executeQuery("CREATE DATABASE TestDB");

    Can someone tell my why ?? I am sure I am missing something.

    Important: this method will still create the database somehow.

    Java Code:
        public static boolean createNewDatabase() throws SQLException, ClassNotFoundException {
    
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String connectionUrl = "jdbc:sqlserver://10.10.10.10:1433; user=sa; password=password;";
            Connection con = DriverManager.getConnection(connectionUrl);
    
            boolean databaseStatus = false;
            String createDatabaseQuery;
    
            try {
    
                if (!(con.isClosed())) {
                    Statement createDatabase = null;
                    createDatabase = con.createStatement();
                    
                    ResultSet result = null;
                    result = createDatabase.executeQuery("CREATE DATABASE TestDB");
                    
                    databaseStatus = true;
                }
    
            } catch (SQLException e) {
                /**if (e.getSQLState().equals("S0003")) {
                    JOptionPane.showMessageDialog(frame, "Database TestDB already exists. Abording database deployment.");
                    databaseStatus = false;
                }*/
                System.out.println(e.getMessage().toString());
            }
            return databaseStatus;
        }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    executeQuery.
    "Executes the given SQL statement, which returns a single ResultSet object. "

    It's intended for SELECT statements.

  3. #3
    pi4r0n is offline Member
    Join Date
    Jan 2011
    Posts
    19
    Rep Power
    0

    Default

    LOL :) stupid mistake I have removed ResultSet result = null; statement :)

    Thanks Tolls for you help :)

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Well no.
    You still shouldn't be using executeQuery.
    You should be using executeUpdate.

Similar Threads

  1. How to return a null result??
    By Yakg in forum New To Java
    Replies: 6
    Last Post: 12-07-2010, 08:38 PM
  2. Return result from JOptionPane to JFrame
    By cselic in forum AWT / Swing
    Replies: 25
    Last Post: 05-15-2010, 08:40 AM
  3. Replies: 8
    Last Post: 12-17-2009, 11:37 AM
  4. there is no return statement
    By gabriel in forum New To Java
    Replies: 17
    Last Post: 12-03-2008, 04:55 PM
  5. H2 Database Engine 1.0.75 (2008-07-14)
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 07-19-2008, 04:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •