Hi been working with connecting to access database for a few days now and thought i'd mastered it but judging by the following - obviously not!
My code is supposed to get a string from text box and get a string from a selection of a jcombobox (search keyword from column) and create a results table (via a new class) after querying the database. I'm not getting any errors and i know (via a if statment that resultSet != null but my print statement in the while loop doesn't ever print - while(result.ne xt()). no new class(pop up jframe) is ever created.
Any help is appreciated - my code is quite messy at the momoment after trying to find out the problem myself. so sorry about that
I now know the new class is being created it, the setvisible(true ) wasn't til the last line in the constructer and it wasn't getting that far because the table it's meant to receive is null.
So the code below isn't creating any data for the jtable - if(obj.equals(searchButton))
-
{
-
String keyword = searchField.getText();
-
String columnSearch = (String)combo.getSelectedItem();
-
try
-
{
-
//s.close();
-
//con.close();
-
String dbURL = "jdbc:odbc:" + "pWarehouseDatabase";
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
Connection con = DriverManager.getConnection(dbURL, "","");
-
Statement s = con.createStatement();
-
// s.execute("INSERT INTO customers//(name, address, email, phone, purchase)");
-
System.out.println(columnSearch + keyword);
-
//s.execute("INSERT INTO customers values(?,'" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')");
-
//String query = "INSERT INTO customers(id, customerName, customerAddress, customerEmail, customerNumber, customerPurchase) values(?, '" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')";
-
Boolean test = s.execute("SELECT * FROM customers WHERE '" + columnSearch + "' = '" + keyword + "'");
-
-
//s.execute("SELECT * FROM customers WHERE 'customerFirstName' = 'hope'");
-
ResultSet resultSet = s.getResultSet(); // get any ResultSet that came from our query
-
-
ResultSetMetaData metaData = resultSet.getMetaData();
-
int numberOfColumns = metaData.getColumnCount();
-
Vector columnNames = new Vector();
-
for(int column = 0; column < numberOfColumns; column++)
-
{
-
columnNames.addElement(metaData.getColumnLabel(column+1));
-
}
-
Vector rows = new Vector();
-
if(resultSet == null)
-
{
-
-
}
-
while (resultSet.next())
-
{
-
System.out.print(test);
-
System.out.println("TEST");
-
Vector newRow = new Vector();
-
for (int i = 1; i <= metaData.getColumnCount(); i++)
-
{
-
newRow.addElement(resultSet.getObject(i));
-
}
-
rows.addElement(newRow);
-
-
}
-
JTable table = new JTable(rows, columnNames);
-
-
-
-
s.close();
-
con.close();
-
//dispose();
-
SearchResults results = new SearchResults(table);
-
-
-
}
-
catch(Exception p)
-
{
-
-
}
-
-
-
-
-
-
-
}
2 1511
1.) Here are some tips.
Don't swallow up exceptions with
The least you should do is to put p.printStackTra ce(); in the catch block so you get told critical information about the exception(s) if any.
2.) Close those connections in a finally block instead. If any exception occurs your con.close statement will never be executed.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steverino |
last post by:
Hi,
I'm currently trying to learn DB2. I have the following version
below installed on my server machine on my little LAN. However when I
try to connect to it from my client machine, I receive the following
error:
CLI0621E Unsupported JDBC server configuration.
Everything I've read on the net though pertains to a Unix based setup
|
by: global |
last post by:
Hi, can anyone help me
I'm on Linux with UDB Runtime-Client 8.1.4 and try to connect to
a windows udb-server 8.1.4 via Websphere and jdbc , and get this
error:
3e1a29e5 WebGroup E SRVE0026E:
-: java.lang.UnsatisfiedLinkError:
SQLConnect
at COM.ibm.db2.jdbc.app.DB2Connection.connect(DB2Connection.java:514)
at COM.ibm.db2.jdbc.app.DB2Connection.<init>(DB2Connection.java:436)
|
by: Dani |
last post by:
Hi everyone
Description of the problem:
Using a PreparedStatement to write down an integer (int) plus a
timestamp for testing purposes. When read out again the integer looks
very different. We found that it was shifted three Bytes to the left,
i.e. 4 becomes hex 4000000 which is 67108864 in decimal base. This
means that the value written and the value read sometimes do not
match, which is of course inacceptable for all real world...
|
by: Bing |
last post by:
Hi,
I am configuring the same DB2 v8.1 JDBC universal driver (db2jcc.jar
and db2jcc_license_cisuz.jar) from DB2 SP5 fix pack under WSAD 5.1.x
environment and WebSphere application Server 5.0.2 on Windows 2000
machines. I configured a connection pool data source using type 4 for
a local test environment in WSAD 5.1.x, and a connection pool data
source on the WebSphere Server too. Both data sources are accessing
the same database.
|
by: Steffen |
last post by:
hi there,
i have a problem connecting to a db2 database 7.2.4 on AIX using java
when running the javacode on AIX using jdk1.3.1.
The classpath is correctly set to java12/...
on windows the following code works fine for the same database:
DB2XADataSource db2 = new DB2XADataSource();
db2.setDatabaseName("MYDB");
| |
by: Olivier |
last post by:
Hello,
Firstly all apologize for my english.
Secondly, I've got some problems to connect to a DB2 database with
JDBC client.
My configuration is :
- DB2 8.1 on an AIX server (name rs26 for the further example)
|
by: Praveen |
last post by:
Hi,
I have installed WebSphere Portal on AIX and connected to DB2 on a
remote machine, Getting the followin errors when trying to get the
values from database thru applications installed on Portal.
Any Help Appreciated.
Thanks in advance.
Praveen Singh
|
by: rpm45tech |
last post by:
Hi everyone. I'm deveolping in Java with DB2 running on Win XP and everything was working ok but then I installed Vista Ultimate and the application stopped working. This is the exception showed:
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'COM.ibm.db2.jdbc.app.DB2Driver' for connect URL...
|
by: SagittaDeveloper |
last post by:
Hi,
I'm have a problem connecting to IBM Universe via JDBC. When I run
the connection code to UV from a none web application it connects and
returns data. When I use the same connection code in my web
application it fails. The same thing haoppenes when I using Suns JDBC
to ODBC bridge.
I'm using:
Tomcat 5.5
|
by: bevis |
last post by:
I'm new to sql server and mysql but this seems like it should be a pretty straight forward jdbc connection. But I have spent almost 2 days just trying to get a jdbc connection. Please help if you can.
I'm using Eclipse 3.2.2 and I have installed mysql-connector-java-5.0.6-bin.jar. I am trying to connect to SQL Enterprise Manager version 8.0 innstall on a Windows 2003 Server Enterprise Edition.
I have been able to successfully test...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |