473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

JDBC Help

153 100+
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.next()). 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 1491
brendanmcdonagh
153 100+
sorted it now thanks
Jun 21 '09 #2
r035198x
13,262 8TB
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.printStackTrace(); 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
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...
0
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...
4
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...
0
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...
5
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...
4
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...
1
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...
1
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: ...
0
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...
2
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.