wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes show database on applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "show database on applet" Watch "show database on applet" New topic
Author

show database on applet

Raj
Greenhorn

Joined: Apr 08, 2007
Posts: 20
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
In which line of code does the NPE occur?


Ping & DNS - my free Android networking tools app
Raj
Greenhorn

Joined: Apr 08, 2007
Posts: 20
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
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
So is the "st" object actually null?
Raj
Greenhorn

Joined: Apr 08, 2007
Posts: 20
//con database var
Statement st;
Connection con;

these are the two variables i have used
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
Where are you setting "st"?
Raj
Greenhorn

Joined: Apr 08, 2007
Posts: 20
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
Have you verified that "st" is null, even though it gets assigned a value?
Raj
Greenhorn

Joined: Apr 08, 2007
Posts: 20
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

Joined: Apr 08, 2007
Posts: 20
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

Joined: Apr 08, 2007
Posts: 20
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
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
Instead of

use

to get rid of the ArrayOutOfBoundsException.
Raj
Greenhorn

Joined: Apr 08, 2007
Posts: 20
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: show database on applet
 
Similar Threads
Need help in Connecting my MySQL Database to JTable in Eclipse.
MetaData question
why cannot get the value in string!!!
printing on an applet
Error java util NoSuchElementException