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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:04:52+00:00 2026-05-11T18:04:52+00:00

I am trying to use JDBC and my query is working in some cases

  • 0

I am trying to use JDBC and my query is working in some cases but not working in others.
I would really appreciate any help.

Some of my code:

public Result getSpecificTopic()
    {
        String query = "Select msg_body, msg_author from lawers_topic_msg";// where msg_id=2 order by msg_id desc";
         try
        {
            con = mysql.getConnection();
            //Statement stmt = con.createStatement();
            PreparedStatement stmt = con.prepareStatement(query);
            //stmt.setInt(1, topicId);
            ResultSet rs = stmt.executeQuery(query);
            int rowCount = rs.getRow();
            specificTopic = ResultSupport.toResult(rs);

            con.close();
            stmt.close();
        }
        catch(Exception e)
        {
        }
        return this.specificTopic;
    }

    public void setTopicId(String num)
    {
        this.topicId = Integer.parseInt(num);
    }

    public int getTopicId()
    {
        return this.topicId;
    }

However if i change

String query = "Select msg_body, msg_author from lawers_topic_msg";

to the

String query = "Select msg_body, msg_author from lawers_topic_msg where msg_id = " + topicId; 

Then the resultset retunrs nothing….
I am breaking my head here and still cannot figure out what is the problem

  • 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-11T18:04:52+00:00Added an answer on May 11, 2026 at 6:04 pm

    As a first step, it’d be worth making sure an exception’s not being thrown – at the very least log something in your catch() block.

    Also be worth logging the SQL generated, and making sure that actually returns what you expect from the database when running it directly.

    If you have multiple databases, it’d be worth confirming you’re running against the one you think you are – I’m embarrassed to admit I’ve been caught out that way before.

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

Sidebar

Related Questions

Trying to use GnuPG with Delphi (Win32). I need to sign some file with
trying to use regex to replace any white space with  , inside of example
Am trying to use MSSQL server with Play Framework, In my application.conf db.url=jdbc:microsoft:sqlserver://localhost\SQL2008:1433;DatabaseName=testDB db.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
I am trying to use DBUnit with plain JDBC and HSQLDB, and can't quite
I was trying to use the JDBC to connect to my MySQL database in
I'm trying to use hibernate with spring 3 mvc but at the moment I
I'm trying to run this simple query over a JDBC connection: select _fk_DeptBillTo from
I am trying to use an external mysql database in my java application, but
I'm trying to use nested queries with JdbcTemplate but found the issue, it seems
I'm trying to run jasper reports against a live and reporting database, but any

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.