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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:45:14+00:00 2026-06-01T21:45:14+00:00

I have been toiling with this issue all day. After reading the benefits between

  • 0

I have been toiling with this issue all day.
After reading the benefits between Statements(S) and PreparedStatements(PS) I decided to convert all my S’s to PS’s in Netbeans.
I was astounded to see that there were no errors but…no output from the execution of my code either.

import java.sql.*;
public class ViewingMySQL {
public static void main(String[] args) {

 //Declare Variables
 Connection con;
 ResultSet rs;
 Statement stmt;
 String sqlappname;

 PreparedStatement findAppID_lookup= null;
 String findAppID_lookup_stmt="select app.ID as APPID" 
 +" from IntergraphIN_AppTranslation" 
 +" inner    join app on app.unit=IntergraphIN_AppTranslation.UnitName" 
 +" where IntergraphIN_AppTranslation.IntergraphUnitName=(?)";

try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:odbc:database","username","password");
sqlappname="'XXXY01'";
findAppID_lookup= con.prepareStatement(findAppID_lookup_stmt);
findAppID_lookup.setString(1, sqlappname);
rs = findAppID_lookup.executeQuery();

if(rs.next()){
System.out.println(rs.getInt("APPID"));
}

rs.close();
findAppID_lookup.close();

}
 catch(Exception e){
 System.err.println(e);
 }
}
}`

When the above code executes and builds…without output.
run:
BUILD SUCCESSFUL (total time: 1 second)

What I had originally was:

import java.sql.*;

public class ViewingMySQL {

public static void main(String[] args) {
//Declare Vars
Connection con;
ResultSet rs;
Statement stmt;
String sqlappname;

try{

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:odbc:Database","username","password");

sqlappname="'XXXY01'";

stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                            ResultSet.CONCUR_READ_ONLY);

rs = stmt.executeQuery("SELECT ID FROM app where AppName="+sqlappname);
if(!rs.isBeforeFirst()){
    rs.close();
    rs = stmt.executeQuery("select app.ID from IntergraphIN_AppTranslation"
    +" inner join app"
    +" on app.unit=IntergraphIN_AppTranslation.UnitName"
    +" where IntergraphIN_AppTranslation.IntergraphUnitName="+sqlappname);
}

if(rs.next()){
System.out.println(rs.getInt(1));
}
rs.close();
stmt.close();
con.close();
}catch(Exception e){
System.err.println(e);
}
}
}`

This code outputs:
run:
2020603
BUILD SUCCESSFUL (total time: 1 second)

The Int that you see above is the ID of the column that I’m looking for.

Can someone please help me with understanding what I’m doing…is it the formatting of the variable that I’m passing into the PS?
Thanks,
SCorliss

  • 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-01T21:45:15+00:00Added an answer on June 1, 2026 at 9:45 pm

    Change this:

    sqlappname="'XXXY01'";
    

    to this:

    sqlappname="XXXY01";
    

    UPDATE re comments:

    PreparedStatements have multiple benefits. For example:

    • it can help protect from sql injection: the input is bound to a variable, the input is not used to create the statement

    • the rdbms can probably make use of statement caching if only the bind variables change (rather than changing the sql statement itself)

    • the statements can be a lot easier to read: you don’t have to mess around with quoting quotes etc

    In this case it seems the meaning of the quoting became confused. In the original: sqlappname=”‘XXXY01′”, the double quote was to declare the java String, the single quote the sql string. In the prepared version: sqlappname=”XXXY01″, we are just saying “this is the String to bind” and we specifiy on the prepared statement that our bind is going to be a String.

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

Sidebar

Related Questions

I have been tooling around with this all day and can't figure it out...
Have been struggling all day trying to make this simple example work using socket.io.
Have been reading about async and tasks and been attempting to convert the CopyFileEx
Have been stuck with this issue for a few days now, and really need,
I have been trying this for the whole day and I managed to make
Have been working on this question for a couple hours and have come close
Have been searching how to convert a dictionary to a string. But the results
Have been trying to fix this problem I have here. Basically I have a
Have been getting pretty bald over this situation! I am using MS VS 2010
Have been trying the whole day long and googled the **** out of the

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.