Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:48:35+00:00 2026-06-18T00:48:35+00:00

I am having a small problem while I try to insert some data in

  • 0

I am having a small problem while I try to insert some data in my database (MS – SQL).
I am using this code (I just copy-paste all of it, so someone might understand smth that I don’t)

 try 
              {
                  Connection connection = null;
                  Statement Statement = null;
                  ResultSet ResultSet = null;
                  String query = "";

              // jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]
              String host = "jdbc:sqlserver://server;databaseName=db";
              String username = "user";
              String password = "pass";
              Statement = connection.createStatement();
              DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
              Calendar cal = Calendar.getInstance();

              DateFormat dateFormat1 = new SimpleDateFormat("dd.MM.yyyy");
              Calendar cal1 = Calendar.getInstance();

              for (int k = 0; k < idArray.length ; k ++ )
              {
                  query = "INSERT INTO Companies (ID,Company,Company2,Company3,Country,ZIP,City,Street," +
                        "Phone,Fax,Email,Internet,CustomerNo,AccountMngr,Icon,AddressSource," +
                        "UserDefined1,UserDefined2,CreatedOn,CreatedBy,ColectedInformation) " +
                        " VALUES ('" + UUID.randomUUID() + "','" + company_nameArray[k] 
                                + "','" + company_name2Array[k] + "','" + company_name3Array[k] + "','DE','"   
                                + zipArray[k] + "','" + cityArray[k] + "','" + streetArray[k] + "','"  
                                + phone_Array[k] + "','" + faxArray[k] + "','" + emailArray[k] + "','"
                                + internetArray[k] + "','" + customer_noArray[k] 
                                + "','d','131','60','Baufinder Import','Import Datum "
                                + dateFormat1.format(cal1.getTime()) + "','" 
                                + dateFormat1.format(cal1.getTime()) + "','d','" 
                                + "cxcxvcx" +  
                                "')";

                  ResultSet = Statement.executeQuery(query);   
              }

              connection.close();
          }
          catch(NullPointerException e)
          {
                System.out.println("NullPointerException");
          }
          catch ( SQLException err ) 
          {
              System.out.println( "SQL Exception:" ) ;

              // Loop through the SQL Exceptions
              while( err != null )
                 {
                  System.out.println( "State  : " + err.getSQLState()  ) ;
                  System.out.println( "Message: " + err.getMessage()   ) ;
                  System.out.println( "Error  : " + err.getErrorCode() ) ;

                  err = err.getNextException() ;
                 }
          }
          catch( Exception e )
          {
              System.out.println( "There is a problem with " + e ) ;
          }

    }

and I am getting this error:

SQL Exception: State : null
Message: There was no result set returned by the statement.
Error : 0

I don’t understand the problem with the result test. I have been using it a lot, since I try to read the data from another database and now I try to insert them to another.
Furthermore, all of these tables do not include null values.

Thank you in advance:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:48:37+00:00Added an answer on June 18, 2026 at 12:48 am

    Use Statement#executeUpdate(String) instead of Statement#execute(query);

    for (int k = 0; k < idArray.length ; k ++ )
              {
                  query = "INSERT INTO Companies (ID,Company,Company2,Company3,Country,ZIP,City,Street," +
                        "Phone,Fax,Email,Internet,CustomerNo,AccountMngr,Icon,AddressSource," +
                        "UserDefined1,UserDefined2,CreatedOn,CreatedBy,ColectedInformation) " +
                        " VALUES ('" + UUID.randomUUID() + "','" + company_nameArray[k] 
                                + "','" + company_name2Array[k] + "','" + company_name3Array[k] + "','DE','"   
                                + zipArray[k] + "','" + cityArray[k] + "','" + streetArray[k] + "','"  
                                + phone_Array[k] + "','" + faxArray[k] + "','" + emailArray[k] + "','"
                                + internetArray[k] + "','" + customer_noArray[k] 
                                + "','d','131','60','Baufinder Import','Import Datum "
                                + dateFormat1.format(cal1.getTime()) + "','" 
                                + dateFormat1.format(cal1.getTime()) + "','d','" 
                                + "cxcxvcx" +  
                                "')";
    
                  int updatedRowCount = Statement.executeUpdate(query);   
              }
    

    Notes:

    1. Please consider using PreparedStatement to prevent possibility of SQL Injection if some data directly input by User.
    2. Try to use batch insert if you need to improve performance of inserting.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a small problem. I have this grid with a column: <data:DataGrid ColumnHeaderStyle={StaticResource
I'm having a problem with NamedPipeServerStream - when my code reads data it's just
Im having a small problem with my code. I have been trying to read
i am having a small problem with my android application. I have some mp3
Using Apache POI to generate a document and i'm having a small problem with
Hey, I've been having this problem for a while now and I was hoping
Im having a small problem i searched a while about it but didnt found
I'm developing a small application but I'm having problem while deploying the application on
Having an annoying small problem. Cannot find the solution that works tried just about
I encountered a code design problem while working on a small application. In terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.