Help me regarding this topic

S

smart

Hi, to all i am new to core java and question on Swings. See this code
and help me.

I want to calculate student marks and his average. When i click button
total marks will have calculate and i am posting code below


Thanks



if(ae.getSource()==btnCal)
{



btnNew.setEnabled(true);
btnSave.setEnabled(false);
btnDel.setEnabled(true);
Connection conSno;
Statement stSno;
int Total,Average;
int English = Integer.praseInt(tfEng.getText());
int Telugu = Integer.praseInt(tfTel.getText());
int Mathmatics = Integer.praseInt(tfMaths.getText());
int Science = Integer.praseInt(tfSci.getText());
int Social = Integer.praseInt(tfSoc.getText());
int Hindi = Integer.praseInt(tfHin.getText());


Class.forName("sun.Jdbc.Odbc.JdbcOdbcDriver");
conSno =
DriverManager.getConnection("jdbc:eek:dbc:DRIVER{Microsoft Access
Driver(*.mdb)};DBQ=D:\\ProgressReport.mdb");


Total = English+Telugu+Mathmatics+Science+Social+Hindi;

Average = Total / 6;

tfTot.setText(String.ValueOf(Total));
tfAvg.setText(String.ValueOf(Average));

stSno=conSno.createStatement();

ResultSet rsSno=stSno.executeQuery("select Tot,Avg from
ProgressReport where Sno = '"+Sno+"'");

if(rsSno.next())
{

tfTot.setText(rsSno.getString(12));
tfAvg.setText(rsSno.getString(13));

} // end of the if condition
} // end of the btnCal
 
A

Andrew Thompson

Sub: Help me regarding this topic

How is it a 'smart' person can create such a dumb subject
line? (That is a question - you can tell by the addition
of the '?' question mark.)

For this post, even a simple subject line of
'average student marks - Swing' would have
been better.
Hi, to all i am new to core java and question on Swings.

It is *Swing* - no final 's'.
..See this code and help me.

It is not considered good form to issue commands
to people. Adding a 'please' at the beginning of
the sentence turns that command into a request.
I want to calculate student marks and his average. When i click button
total marks will have calculate and i am posting code below

OK - what is your question?

A couple of notes:
- You have a lot greater chance of getting an
answer if you include short but *compilable* code.
- Please indent code with 2-4 spaces per indent level,
not the large indents which will force line-wrap.
- Now I glance at the snippet I notice 'Telugu' from
the other day, and (checking) you were the person
that asked that question. A variety of things were
suggested to you, including to conform to the coding
(naming) conventions that other programmers expect.
Why did you ignore that advice? Do you intend to
waste the time and effort of the people who are
trying to help?
- People here will not 'finish your homework' for you.
To get good values from these groups, you need to
ask *specific* questions - we are not some kind of
'homework help-desk'.
 
R

RedGrittyBrick

smart said:
Hi, to all i am new to core java and question on Swings. See this code
and help me.

We can only help if you tell is what you think is going wrong.
- is there a compiler error message?
- is there a run-time error message?
- does the output differ from what you expect? How exactly?
I want to calculate student marks and his average. When i click button
total marks will have calculate and i am posting code below

I think you really should pay attention to what Andrew and others have
said about formatting your source code - I find it hideously unreadable.


if(ae.getSource()==btnCal)

Looks like this is part of some event handler like an ActionListener.
It's a shame you don't provide a complete (but small) example program.
{



btnNew.setEnabled(true);
btnSave.setEnabled(false);
btnDel.setEnabled(true);
Connection conSno;
Statement stSno;

Presumably those are java.sql.Connection and java.sql.Statement - I
recommend you read about Model-View-Controller (MVC) patterns and try to
keep database code in separate classes from your GUI code.

int Total,Average;

That level of indentation is ridiculous, please convert tabs to two
(maybe four) spaces before posting. Most editors and IDEs I've used
allow you to configure them so that tabs are always converted to spaces.

Cariable names should start with lower case ("english" instead of
"English") otherwise you confuse readers by making variable names look
like class names.
int English = Integer.praseInt(tfEng.getText());
int Telugu = Integer.praseInt(tfTel.getText());
int Mathmatics = Integer.praseInt(tfMaths.getText());
int Science = Integer.praseInt(tfSci.getText());
int Social = Integer.praseInt(tfSoc.getText());
int Hindi = Integer.praseInt(tfHin.getText());

I'd have an array or HashMap of JTextFields to eliminate this repetition.

Class.forName("sun.Jdbc.Odbc.JdbcOdbcDriver");
conSno =
DriverManager.getConnection("jdbc:eek:dbc:DRIVER{Microsoft Access
Driver(*.mdb)};DBQ=D:\\ProgressReport.mdb");

See above. Anyway, your JDBC code seems to be scattered around
incoherently, I'd gather it all up in one place.

Total = English+Telugu+Mathmatics+Science+Social+Hindi;

Average = Total / 6;

tfTot.setText(String.ValueOf(Total));
tfAvg.setText(String.ValueOf(Average));

stSno=conSno.createStatement();

ResultSet rsSno=stSno.executeQuery("select Tot,Avg from
ProgressReport where Sno = '"+Sno+"'");

if(rsSno.next())

I usually use while(xxx.next()) unless I have specifically checked that
only one record will be returned.
{

tfTot.setText(rsSno.getString(12));
tfAvg.setText(rsSno.getString(13));

getString(12) will not return anything useful since your SQL statement
only selects two fields from the table.

You are overwriting the text in tfTot, which you just put your
calculated total into. It is no surprise you don't ever see the
calculated total - I guess that is the actual problem (which you failed
to say).
} // end of the if condition
} // end of the btnCal


Unless you pay some attention to the advice about tabs and
capitalisation, I will find it very hard to summon the will to respond
any further.
 
H

Hal Rosser

int English = Integer.praseInt(tfEng.getText());
int Telugu = Integer.praseInt(tfTel.getText());
int Mathmatics = Integer.praseInt(tfMaths.getText());
int Science = Integer.praseInt(tfSci.getText());
int Social = Integer.praseInt(tfSoc.getText());
int Hindi = Integer.praseInt(tfHin.getText());

To start with, I don't think Integer has a praseInt method.
I may be wrong, but spelling counts a lot in Java.
 
D

David Zimmerman

Hal said:
To start with, I don't think Integer has a praseInt method.
I may be wrong, but spelling counts a lot in Java.
I think he has it right. The great Int god needs much prasing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top