473,805 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JDBC Help

153 New Member
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

Expand|Select|Wrap|Line Numbers
  1. if(obj.equals(searchButton))
  2.              {
  3.              String keyword = searchField.getText();
  4.              String columnSearch = (String)combo.getSelectedItem();
  5.              try
  6.                 {
  7.                     //s.close();
  8.                     //con.close();
  9.                     String dbURL = "jdbc:odbc:" + "pWarehouseDatabase";
  10.                     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  11.         Connection con = DriverManager.getConnection(dbURL, "","");
  12.         Statement s = con.createStatement();
  13.                // s.execute("INSERT INTO customers//(name, address, email, phone, purchase)");
  14. System.out.println(columnSearch + keyword);
  15.             //s.execute("INSERT INTO customers values(?,'" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')");
  16.            //String query = "INSERT INTO customers(id, customerName, customerAddress, customerEmail, customerNumber, customerPurchase) values(?, '" +name + "','" + address + "','" + email + "','" + phone + "','" + purchase + "')";
  17. Boolean test = s.execute("SELECT * FROM customers WHERE '" + columnSearch + "' = '" + keyword + "'");
  18.  
  19. //s.execute("SELECT * FROM customers WHERE 'customerFirstName' = 'hope'");
  20. ResultSet resultSet = s.getResultSet(); // get any ResultSet that came from our query
  21.  
  22.         ResultSetMetaData metaData = resultSet.getMetaData();
  23.                int numberOfColumns =  metaData.getColumnCount();
  24.                Vector columnNames = new Vector();
  25.                for(int column = 0; column < numberOfColumns; column++)
  26.                {
  27.                      columnNames.addElement(metaData.getColumnLabel(column+1));
  28.                }
  29.                Vector rows = new Vector();
  30.                if(resultSet == null)
  31.                {
  32.  
  33.                }
  34.                while (resultSet.next())
  35.                {
  36.                    System.out.print(test);
  37.                    System.out.println("TEST");
  38.                     Vector newRow = new Vector();
  39.                     for (int i = 1; i <= metaData.getColumnCount(); i++)
  40.                     {
  41.                          newRow.addElement(resultSet.getObject(i));
  42.                     }
  43.                     rows.addElement(newRow);
  44.  
  45.                }
  46.                JTable table = new JTable(rows, columnNames);
  47.  
  48.  
  49.  
  50.         s.close(); 
  51.         con.close();
  52.         //dispose();
  53.         SearchResults results = new SearchResults(table);
  54.  
  55.  
  56.              }
  57.              catch(Exception p)
  58.              {
  59.  
  60.              }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.     }
Jun 20 '09 #1
2 1511
brendanmcdonagh
153 New Member
sorted it now thanks
Jun 21 '09 #2
r035198x
13,262 MVP
1.) Here are some tips.
Don't swallow up exceptions with
Expand|Select|Wrap|Line Numbers
  1. catch(Exception p)
  2.  {
  3. }
  4.  
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.
Jun 22 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
6063
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
0
1978
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)
4
6352
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...
0
3087
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.
5
5632
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");
4
4127
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)
1
9036
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
1
8804
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...
0
2567
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
2
4560
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...
0
9718
marktang
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...
0
10613
Oralloy
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...
0
10107
tracyyun
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...
1
7649
isladogs
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...
0
6876
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();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
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
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.