• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

show database on applet

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys,

i have solved all problems of sign my apllet using keytool and jarsigner
but i am still facing problems displaying contents of my database (ms access) on to d applet.

the methid to retrive data is as follows

private void RetrieveData ()
{
try
{
ResultSet rs = st.executeQuery("Select * from MediInfo");

ResultSetMetaData md = rs.getMetaData();
int colcount = md.getColumnCount();

Object[] data = new Object[colcount];

while (rs.next())
{
for (int i=1; i<=colcount; i++)
{
data[i-1] = rs.getString(i);
}
}
}
catch(Exception e) {System.out.println(e);}
}
the java console shows null pointer exception.

please help

regds
anc_k
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In which line of code does the NPE occur?
 
Raj
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when ever i call RetrieveData () there is an npe which is shown on the java console apparently on d first line.
will this function print my data entries on the applet or do i have to use some other method
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So is the "st" object actually null?
 
Raj
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//con database var
Statement st;
Connection con;

these are the two variables i have used
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you setting "st"?
 
Raj
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you verified that "st" is null, even though it gets assigned a value?
 
Raj
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well i did try system.out.println and it is showing null :roll: soooo is it not connecting to my database?
what should i do
 
Raj
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wait wait its not showing null the output is
sun.jdbc.odbc.JdbcOdbcStatement@1a0c10f
when i just call connecttodatabase()

and this is a modified retrive data which is printing d values of data[i]
on the console




and this is the output
refresh pressed
null
null
null
java.lang.ArrayIndexOutOfBoundsException: 4


please help
 
Raj
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wait wait its not showing null the output is
sun.jdbc.odbc.JdbcOdbcStatement@1a0c10f
when i just call connecttodatabase()

and this is a modified retrive data which is printing d values of data[i]
on the console




and this is the output
refresh pressed
null
null
null
java.lang.ArrayIndexOutOfBoundsException: 4


please help
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of

use

to get rid of the ArrayOutOfBoundsException.
 
Raj
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the point is that data[] is not takin any values in it [showin null]. colcount variable is accepting the no of coloumns in datbase (i changed the no of coloumns in d data base and the there was a change in colocount variable too ) hence the program is reading my database only problem is the values inside the table are not retrived.
ie data is returning null.

is there any other method than getstring() which i can use to read data fom my database.
reply
    Bookmark Topic Watch Topic
  • New Topic