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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:12:19+00:00 2026-06-14T22:12:19+00:00

I really don’t know what’s going on. I’m new to Java, fairly new to

  • 0

I really don’t know what’s going on. I’m new to Java, fairly new to MySQL.

I am trying to insert rows into a MySQL database in Java. It’s not throwing any exceptions, and when I print out a SELECT * it’s showing me the rows I updated. But those rows aren’t sticking when I run the program again or in Workbench.

One of the columns (the pk) is an auto incremented field. This field is being incremented, but the data isn’t there.

When I add data though Workbench, it sticks and I can retrieve it in my Java program when I do a SELECT *. It’s only when I add it through the code below, that the data seems to disappear.

Here is the code. I followed a tutorial:

import java.sql.*;

public class SaveMap {  
public static boolean MapSave(String mapName) {
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    String url = "jdbc:mysql://127.0.0.1:3306/";
    String db = "game_Maps";
    String driver = "com.mysql.jdbc.Driver";
    String user = "root";
    String pass = "pass";

    try {
        Class.forName(driver);
        con = DriverManager.getConnection(url + db, user, pass);
        con.setAutoCommit(false);

        st = con.createStatement();

        System.out.println(st.executeUpdate("INSERT INTO Maps (mapName, mapSize) VALUES('DB Test', 5)"));
        st.executeBatch();



        String sql = "SELECT * FROM Maps";
        rs = st.executeQuery(sql);

        System.out.println("No \t Name");
        while(rs.next()){
            System.out.println(rs.getString(1) + " \t");
            System.out.println(rs.getString(2) + " \t");
            System.out.println(rs.getString(3) + " \t");
        }

        rs.close();
        st.close();
        con.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return true;
}
}
  • 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-14T22:12:20+00:00Added an answer on June 14, 2026 at 10:12 pm

    It’s because you set auto commit to false (con.setAutoCommit(false);), but didn’t commit the transaction.

    Non comitted inserts do not store the row, but they do increment auto increment fields.

    You need to commit the transaction for the rows to stay after the transaction ends.

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

Sidebar

Related Questions

I really don't know what's going on with my configuration, but I'm just not
I really don't know squat about java memory management, so this is entirely my
I really don't know how to explain what's going on, so I'll just show
I'm new to python so I really don't know the language very well. the
I really don't know what's wrong here and why it isn't recreating the new
I really don't know what i'm doing wrong. I want to count the rows
I really don't know how to express this question. But what I'm trying to
I really don't know what is going on. It worked the first time, then
Not really sure how to ask this question because I really don't know what
I really don't even know where to begin. I was trying to do some

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.