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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:43:37+00:00 2026-05-27T16:43:37+00:00

I want to run an SQL file that has a lot of Insert Statments,

  • 0

I want to run an SQL file that has a lot of Insert Statments, and I am trying to run the file, So far i found this code but its not that good as it gives me an error that the table is not found, can you have a look at the code maybe you can find the problem ?

      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)                    {                                         
    try {                                         

        URL = jTextField1.getText();
        username = jTextField3.getText();
        password = jTextField2.getText();

        String s = new String();
        StringBuilder sb = new StringBuilder();
        Connection conn = (Connection) DriverManager.getConnection(URL, username, password);
        Class.forName("com.mysql.jdbc.Driver");

        try {
            Statement st = conn.createStatement();
            String query = "DELETE FROM player;";
            st.executeUpdate(query);
            JOptionPane.showMessageDialog(this, "Delete Compleated");
        }catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        }


////////////////////////////////////////////////////////////////////////////////        
        try {

            FileReader fr = new FileReader(new File("player.sql"));
            // be sure to not have line starting with "--" or "/*" or any other non aplhabetical character  

            BufferedReader br = new BufferedReader(fr);

            while ((s = br.readLine()) != null) {
                sb.append(s);
            }
            br.close();

            // here is our splitter ! We use ";" as a delimiter for each request  
            // then we are sure to have well formed statements  
            String[] inst = sb.toString().split(";");


            Statement st = conn.createStatement();

            for (int i = 0; i < inst.length; i++) {
                // we ensure that there is no spaces before or after the request string  
                // in order to not execute empty statements  
                if (!inst[i].trim().equals("")) {
                    st.executeUpdate(inst[i]);
                    System.out.println(">>" + inst[i]);
                }
            }

             JOptionPane.showMessageDialog(this,"Loaded Compleat");

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        }

        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        try {

            Statement st = conn.createStatement();
            String query = "Select * from player;";
            ResultSet rs = st.executeQuery(query);

            while (rs.next()) {
                int d1 = rs.getInt(1);
                String d2 = rs.getString("PlayerName");
                String d3 = rs.getString("PlayerSurname");
                String d4 = rs.getString("PlayingPosition");
                double d5 = rs.getDouble("PlayerRating");

                model.addRow(new Object[]{
                            d1, d2, d3, d4, d5
                        });
            }

            rs.close();
            st.close();
            conn.close();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        }

    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Football.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SQLException ex) {
        Logger.getLogger(Football.class.getName()).log(Level.SEVERE, null,ex);
    }

}     

thx for any help you can give 🙂 i am using Xampp and the database is all ready created all i need is to populate it,

  • 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-27T16:43:38+00:00Added an answer on May 27, 2026 at 4:43 pm

    maybe you have to append new line "\n" in this code

    while ((s = br.readLine()) != null) {
                    sb.append(s);
                    sb.append("\n");
                }
    

    because you append each line right after the before line

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

Sidebar

Related Questions

We have some code that we want to run a BULK INSERT sql command,
I have a sql script file and i want to run that i can
I have a .sql script file that I want to run once every 24
I want to run parameterized SQL with .NET. But when I use AddWithValue() the
Why this code don't work,when i want run this code vwd 2008 express show
I have some code that essentially does what I want but I always like
I am trying to run a stored procedure that has multiple in and out
I want to run a sql query on a specific schedule (weekly) and need
I want to run a script remotely. But the system doesn't recognize the path.
I want to run the following jquery code on every page in my website.

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.