This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

show database on applet

 
Raj
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which line of code does the NPE occur?
 
Raj
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is the "st" object actually null?
 
Raj
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//con database var
Statement st;
Connection con;

these are the two variables i have used
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you setting "st"?
 
Raj
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you verified that "st" is null, even though it gets assigned a value?
 
Raj
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of

use

to get rid of the ArrayOutOfBoundsException.
 
Raj
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic