java


SQL Query Java Net Beans


Basically I have a table name java_db.Customer with the columns CustomerID,
Name, Address and FinanceOK.
Basically I want to write a simple query that says if FinanceOK = true JOptionPane.ShowMessage "Finance Accepted"
Otherwise FinanceOK = False JOptionPane.ShowMessage "Finance Declined".
What is the the best way to go about writing this query?
You seem to need help with SQL query structuring and executing this query via JDBC.
You can start learning SQL query basics with this SQL tutorial.
After that, you need to learn how to execute that query and retrieve the results from Java using the JDBC java specification. I recommend you start with Oracle's official tutorial.
If you still have doubts about specific features or problems, feel free to come back and keep asking until you can get it working! Good luck.
Now, there's a lot of information in your post that is missing but down and dirty here is how you might accomplish the task:
long customerID_Variable = 232; // .... whatever you have to provide customer ID number ....
String customerName = "John Doe"; // .... whatever you have to provide customer name ....
boolean financeOK = false; // default financing approval flag
String message = "Finance Declined!"; //default message
// Catch SQLException if any...
try {
// Use whatever your connection string might be
// to connect to your particular Database....
Connection conn = DriverManager.getConnection("jdbc:derby:c:/databases/salesdb jdbc:derby:salesdb");
conn.setAutoCommit(false);
// The SQL query string...
String sql = "SELECT FinanceOK FROM Customer WHERE CustomerID = " + customerID_Variable + ";";
// Although it is best to use the Customer ID to reference a
// particular Customer you may prefer to to use the Customer
// name and if so then use the query string below instead...
// String sql = "SELECT FinanceOK FROM Customer WHERE Name = '" + customerName + "';";
// Execute the SQL query...
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
//Retrieve the data from the query result set...
while (rs.next()) {
financeOK = rs.getBoolean("FinanceOK");
}
//Close everything...
rs.close();
stmt.close();
conn.close();
}
catch (SQLException ex) { ex.printStackTrace(); }
int msgIcon = JOptionPane.ERROR_MESSAGE;
if (financeOK) {
message = "Finance Accepted!";
msgIcon = JOptionPane.INFORMATION_MESSAGE;
}
JOptionPane.showMessageDialog(null, message, "Financing Approval...", msgIcon);
Hope this helps somewhat.

Related Links

Java Optional.ofNullable with Mockito
reading in text file data to create polygons java
Client's BufferedReader not recieving line from Server, using sockets (Java)
Getting the most “popular” number from array
how can i send the string value into the intent.putextra? [duplicate]
jsoup doesn't fetch the whole pre-tag content
Mapping every URL that has no file extension to a sub-path in Spring Boot?
writing to file with new arrays java
GCM android client not working
GemFire 8.2.0 cluster using static server list in cache.xml
Key with alias xxx doesn't have a private key with Spring SAML
Tomcat WAR deployment creates a 404
What is the best way to create a .java file and build and execute it in programmatically in Java [closed]
How can I add constructor params using Dependency Injection
my app getting crashed when i use this threads codes
Convert numbers in an array to another array

Categories

HOME
blogger
proxy
gremlin
pycharm
include
android-4.4-kitkat
razor
twitter-bootstrap-4
gps
win32gui
alpha
fingerprint
uber-api
maude-system
u-sql
msp430
dynamics-crm-online
ghc
transformation
http-status-code-504
swiftlint
java-3d
core-text
tibco-mdm
microsoft-r
icloud-api
javacv
user-interaction
brunch
uninstall
rst2pdf
maxmind
fluentvalidation
windows-server-2000
gitignore
twilio-api
pdb
environment-modules
fusionpbx
jquery-bootgrid
ansible-playbook
awt
preconditions
babel-core
skeleton-css-boilerplate
taffy
chain-builder
termination
pango
idisposable
color-profile
webdriverjs
or-tools
yt-project
xcb
color-picker
probability-density
simplewebrtc
hover-over
tcpserver
jmeter-maven-plugin
django-unittest
splash
apache-commons-fileupload
dundas
truevault
tween
camanjs
qpainter
markers
bitcoinj
openexr
datagridviewcolumn
resty-gwt
access-rights
soundtouch
excel-2003
django-nonrel
jquery-mobile-dialog
robotics-studio
clipper
funscript
windows-phone-7.1.1
nsmanagedobject
data-loss
spyware
mod-auth
f#-powerpack
appender
remember-me
blitz++
gallio
web-application-design
thunderbird-lightning
substrings
exchange-server-2003
sustainable-pace

Resources

Encrypt Message