Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 02-05-2011, 11:58 AM   #1 (permalink)
Apprentice
 
iamharish15's Avatar
 
Join Date: Apr 2011
Location: Delhi
Posts: 55
Lightbulb JDBC connectivity with MS Access DB


I am working on a project in which I need to store the information about the users into a Database and based on the querry I need to take the results from the databse and display the results retreived from database in a frame. But I could not put the retrieved information from the database into the frame and display it.
I am using J2SE JDK 1.6 and Netbeans 6.9.1 and MS Access(MS Office 2010 EE).
So please suggest the code or any other solution to it.
iamharish15 is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 02-05-2011, 12:44 PM   #2 (permalink)
Super Moderator
 
asingh's Avatar
 
Join Date: May 2008
Location: New Delhi
Posts: 5,548
Default Re: JDBC connectivity with MS Access DB

I used to do it using AODB. But it supports JDBC too.

Use Microsoft Access with Java - JavaWorld
MS Access JDBC Driver -- Connecting MS Access with Java
__________________
MSI P45 Platinum(BIOS v1.7B)|Q9550[E0]@3.85Ghz@1.320V[453x8.5]MCH@1.184V|ICH@1.55V|DDR_V_Ref_A_B@1.05V|NH-D14|Corsair TWIN2X4096-8500C5(5-5-5-15)@1089Mhz@2.14V
2xHD4890[Xfire]@1000/900[MEM/GPU]|Corsair 650TX|Seagate180GB+80GB+WD1TB|SONY-DVD-R|CM690|2x120mm Scythe Ultra Kaze|DELL S2409W|APC 1100VA|Scythe Kaze Server
Windows 7 Ultimate RTM - 64BIT|Catalyst 10.5 (8.14.10.0753) forced with RadeonPRO|PS3 160GB|Sony 40EX520|AC Ryan POHD Mini|APC 800VA|APC 800VA|D425KT|CM100 Elite|2TB WD|Acer D255

Test your spoiler tags before submitting
asingh is online now   Reply With Quote
Old 02-05-2011, 08:51 PM   #3 (permalink)
Apprentice
 
iamharish15's Avatar
 
Join Date: Apr 2011
Location: Delhi
Posts: 55
Post Re: JDBC connectivity with MS Access DB

this is not the problem i had. I had successfully connected with the access db using jdbc-odbc bridge but i am having trouble retrieving results from that database and display it on the frame or any output device.
for example the project i am working on requires me to take some specific tuples from the DB based on input criteria by the user(viz. firstname) and put it on a frame and displaying it.
Below is a code snippet i am having trouble with:
Quote:
private void PhoneDisplayActionPerformed(java.awt.event.ActionE vent evt) {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbcdbccm"); //pcm is the dsn
PreparedStatement st = con.prepareStatement("select firstname,lastname,email1,city,state,country,mobil e1,home from ContactsInfo"
+ "where firstname=?%");
st.setString(1,jComboBox7.getSelectedItem().toStri ng());
JOptionPane.showMessageDialog(PhoneDisplay,"Retrie ving Results....");
ResultSet rs = st.executeQuery();
int c = rs.getMetaData().getColumnCount();
rs.last();
int r = rs.getRow();
Object[][] data = new Object[r][c];


rs.first();
for(int i=0;i<r;i++)
{
data[i][0] = rs.getInt(1);
data[i][1] = rs.getString(2);
data[i][2] = rs.getString(3);
data[i][3] = rs.getString(4);
data[i][4] = rs.getString(5);
data[i][5] = rs.getString(6);
data[i][6] = rs.getString(7);
data[i][7] = rs.getString(8);
rs.next();
}

Object[] col = {"First Name","Last Name","Email1","City","State","Country","Mobile"," Home No."};
JTable t = new JTable(data,col);
QuerryFrame qf = new QuerryFrame();
qf.add(t);
qf.setSize(500, 600);
qf.setVisible(true);
con.setAutoCommit(true);
con.close();

}
catch (ClassNotFoundException ex) {
//Logger.getLogger(SearchPhone.class.getName()).log( Level.SEVERE, null, ex);
}
catch(SQLException se)
{
//JOptionPane.showMessageDialog(PhoneDisplay,"SQL Exception");
}
iamharish15 is offline   Reply With Quote
Old 03-05-2011, 11:38 PM   #4 (permalink)
Apprentice
 
iamharish15's Avatar
 
Join Date: Apr 2011
Location: Delhi
Posts: 55
Post Re: JDBC connectivity with MS Access DB

When I compiled the above code, it showed no errors but shows a run time exception.
Quote:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParam eter(JdbcOdbcPreparedStatement.java:1023)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setChar(Jd bcOdbcPreparedStatement.java:3057)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setString( JdbcOdbcPreparedStatement.java:766)
at personalcontactmanagement.SearchPhone.PhoneDisplay ActionPerformed(SearchPhone.java:187)
at personalcontactmanagement.SearchPhone.access$100(S earchPhone.java:22)
at personalcontactmanagement.SearchPhone$2.actionPerf ormed(SearchPhone.java:71)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEven tMulticaster.java:272)
at java.awt.Component.processMouseEvent(Component.jav a:6041)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3265)
at java.awt.Component.processEvent(Component.java:580 6)
at java.awt.Container.processEvent(Container.java:205 8)
at java.awt.Component.dispatchEventImpl(Component.jav a:4413)
at java.awt.Container.dispatchEventImpl(Container.jav a:2116)
at java.awt.Component.dispatchEvent(Component.java:42 43)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3916)
at java.awt.Container.dispatchEventImpl(Container.jav a:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2440 )
at java.awt.Component.dispatchEvent(Component.java:42 43)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:121)
When I run the static SQL select command through Statement object, it runs perfectly but when I try to take the parameter at runtime through PreparedStatement object, it shows the above exception.
Please suggest some solution for the above exception.
iamharish15 is offline   Reply With Quote
Old 04-05-2011, 01:33 PM   #5 (permalink)
Excessive happiness
 
furious_gamer's Avatar
 
Join Date: Jun 2008
Location: Bangalore
Posts: 2,974
Default Re: JDBC connectivity with MS Access DB

Did you checked the value "jComboBox7.getSelectedItem().toStri ng()" by printing it?
__________________
My First Android phone : Samsung Galaxy SL i9003 - Rooted & Gingerbread XXKPQ
Updated : superteekz_V2 ROM for XXKPQ.

PS Request
furious_gamer is online now   Reply With Quote
Old 04-05-2011, 05:29 PM   #6 (permalink)
Apprentice
 
iamharish15's Avatar
 
Join Date: Apr 2011
Location: Delhi
Posts: 55
Default Re: JDBC connectivity with MS Access DB

yes I have tried that it is working correctly.
static SQL commands are running good but the dynamic SQL commands with PreparedStatement object is having the trouble...
iamharish15 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:27 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2