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 6775901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:57:44+00:00 2026-05-26T15:57:44+00:00

hi am trying to insert values into SQL database using jdbc. Current code able

  • 0

hi am trying to insert values into SQL database using jdbc. Current code able to connect and query sql DB. am using executeupdate to insert the values .this code is not giving any errors.but values are not getting inserted into SQL DB. how can i insert values into DB???

  import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
  import com.microsoft.sqlserver.jdbc.SQLServerException;
  import java.sql.*;

    import java.sql.Connection;
class New{
Connection connection = null;
void condb() throws SQLServerException, SQLException{

  SQLServerDataSource dataSource = new SQLServerDataSource();
    dataSource.setServerName("OEl");
    dataSource.setPortNumber(1433);
    dataSource.setDatabaseName("Example");
    dataSource.setUser("sa");
    dataSource.setPassword("******");
        connection = dataSource.getConnection();
        connection.setAutoCommit(false);
        System.out.println("Connected to server !!!");
}
 void insertvalues() throws SQLException{
   Statement statement1=connection.createStatement();
                       statement1.executeUpdate("insert into dbo.Company " +
             "values('abc', 2)");

}
public static void main(String args[]) throws SQLServerException, SQLException{
New con=new New();
con.condb();
 con.insertvalues();
}
   }
  • 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-05-26T15:57:45+00:00Added an answer on May 26, 2026 at 3:57 pm

    You’ve set autocommit to false and haven’t committed. What did you think would happen? From Oracle’s own docs on the subject:

    After the auto-commit mode is disabled, no SQL statements are committed until you call the method commit explicitly.

    Either:

    connection.setAutoCommit (true);
    

    when you create the connection (although we can probably discount that as an option since you explicitly set it to false, meaning you wanted to batch up your changes in a transaction), or:

    connection.commit();
    

    before returning from insertValues().

    You may also want to check the return value from executeUpdate even if only for debugging purposes. For an insert, it gives you the number of rows inserted (should be one, in this case).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to insert some values into an sql database. I am using
I am trying to insert certain values into the table using SQL server 2005.
im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
Trying to insert values with Unicode Chars into a MySQL-database using Delphi 2010 and
i'm trying to insert some data on a database using this code: -(void)insertLocationOnDatabase:(LocationType *)aLocation
getting errors when trying to write into a SQL database using the 2 following
I'm using management studio to connect to my sql mobile/compact database. I'm trying to
I am trying to insert an entry into a database using a form created
I am trying to insert a row into a table, using a value that
I am trying to insert values in database and values are not being inserted,

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.