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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:08:11+00:00 2026-06-08T08:08:11+00:00

Can someone help me with this: I’m making a java database application and I

  • 0

Can someone help me with this: I’m making a java database application and I want to put my methods for select,insert,update and delete into separated class so they can be called from another classes and reused.
Till now I managed to separate only methods for update and delete and for insert when not using prepared statement. Problem I’m encountering is how to return data’s when doing select from database and put them into table.

Here are my update and delete method’s in Queries class:

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.Konekcija.Konekcija;

public class Queries {
Konekcija konekcija = new Konekcija();

public void updateTable(String sqlQuery){
    Connection conn = null;
    Statement st = null;
    try{
        Class.forName("com.mysql.jdbc.Driver");
        conn = konekcija.getConn();
        st = conn.createStatement();
        st.executeUpdate(sqlQuery);

    }catch(Exception e){
        e.printStackTrace();
    }finally{
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            st.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

public void deleteFromTable(String sqlQuery){
    Connection conn = null;
    Statement st = null;
    try{
        Class.forName("com.mysql.jdbc.Driver");
        conn = konekcija.getConn();
        st = conn.createStatement();
        st.executeUpdate(sqlQuery);
    }catch(Exception e){
        e.printStackTrace();
    }finally{
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            st.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

}

P.S. Connection properties are in another class “Konekcija”

  • 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-08T08:08:12+00:00Added an answer on June 8, 2026 at 8:08 am

    You should create a collection and populate it with the results of the query, it should look something like:

    List<Foo> selectFoos(Connection connection) throws SQLException {
        PreparedStatement ps = connection.prepareStatement("select * from foo");
        try {
            ResultSet resultSet = ps.executeQuery();
            try {
                List<Foo> foos = new ArrayList<Foo>();
                while (resultSet.next()) {
                    Foo foo = new Foo();
                    // use resultSet methods get... to retrieve data from current row of results
                    // and populate foo
                    foos.add(foo);
                }
            } finally {
                resultSet.close();
            }
        } finally {
            ps.close();
        }
        return foos;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

not able to get this, can someone help for this LINQ query? select col1,
Can someone help me on this. I'm made an image uploader and i want
Can someone help with this exception? Uncaught exception from servlet java.net.SocketTimeoutException: Timeout while fetching:
can someone help with this? I need the following function to do this... $x
Can someone help me with this: This is a program to find all the
can someone help me with this? I have an AlertDialog box and its working
Im a beginner to css, please can someone help me get this element to
Can someone help me out with this one. I have a page, in which
Can someone help me with converting this query to a Linq to entities query
Can someone help me understand how to write this case statement properly its not

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.