• Post Reply Bookmark Topic Watch Topic
  • New Topic

doubts in projects  RSS feed

 
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have an existing project so iam learning the project and wants to implement some other features,i have doubts regarding to project.
it is registration module in that project contains name,sex,email,contact num etc which are placed in jsp,so in servlet accesing the parameter using request.getParameter("name"); see the below coding

 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The max in line 6 is an SQL function. Do you know anything about SQL? The select statement selects the column EmpID from the table EmpDetails, and it selects the highest EmpID that's in the table.

= is the assignment operator, == is the operator you use for comparisons.

Are you working on this project alone, or do you have colleagues? Ask them to explain to you how the code in the project works.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:The max in line 6 is an SQL function. Do you know anything about SQL? The select statement selects the column EmpID from the table EmpDetails, and it selects the highest EmpID that's in the table.

= is the assignment operator, == is the operator you use for comparisons.

Are you working on this project alone, or do you have colleagues? Ask them to explain to you how the code in the project works.

yeah i know about sql,in that database there is no values present so that why i had doubt ,i know about = and == but in the above code int i=0; what it means and if i==0 means what it means,iam working alone on that project i understand but some doubts
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int i = 0; obviously declares a variable named i of type int and initializes it to 0. I don't know what the variable i is used for in the context of this program. Note that in line 14, i is set to whatever new Database().setResultSet(...); returns. You'll have to look at the method setResultSet of the class Database to find out what the return value means.

Looking at lines 16-20, my guess is that it returns the number of records inserted. If 0 records were inserted (that's what's being tested in line 16), it prints "Not Inserted", otherwise it prints " Inserted Successfully".
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:int i = 0; obviously declares a variable named i of type int and initializes it to 0. I don't know what the variable i is used for in the context of this program. Note that in line 14, i is set to whatever new Database().setResultSet(...); returns. You'll have to look at the method setResultSet of the class Database to find out what the return value means.

Looking at lines 16-20, my guess is that it returns the number of records inserted. If 0 records were inserted (that's what's being tested in line 16), it prints "Not Inserted", otherwise it prints " Inserted Successfully".

ok i will check it about i variable if you dont mine will you tell from line 3 to 13 what happens then i will understand whats happening in that project
 
Ranch Hand
Posts: 63
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If line 14 code which is actually insertion in the database executed method will return 1 otherwise 0.
Here max will return the maximum EmpID from EmpDetails.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Zelan wrote:if you dont mine will you tell from line 3 to 13 what happens then i will understand whats happening in that project

What do you think happens in line 3 to 13?

If you have trouble understanding the basics of Java, study a book or check out Oracle's Java Tutorials.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:
Will Zelan wrote:if you dont mine will you tell from line 3 to 13 what happens then i will understand whats happening in that project

What do you think happens in line 3 to 13?

If you have trouble understanding the basics of Java, study a book or check out Oracle's Java Tutorials.


which acessing previous forms

newid has no value(iam not sure)

retrieving the empid values from empdetails,rs.next(); means i dnt know,newid=rs.getString(1) means we just allocating newid as 1st column in the database

so above code which starts from newid as emp100,but newid="" and newid=null is both are different
i=new Database().setResultSet("insert into EmpDetails values(newid,name,sex);

inserting values in the database newid, name and sex


if no value is entered in the database it shows the message not inserted
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will Zelan wrote:
which acessing previous forms

"Accessing previous forms"? What does that mean? These two lines get parameters, presumably from an HttpServletRequest. The parameters probably come from an HTML form which was submitted.

Will Zelan wrote:
newid has no value(iam not sure)

Declares a variable newID of type String and initializes it with "" (the empty string).

Will Zelan wrote:
retrieving the empid values from empdetails,rs.next(); means i dnt know,

Lookup the API documentation of java.sql.ResultSet and Oracle's JDBC tutorial.

Will Zelan wrote:newid=rs.getString(1) means we just allocating newid as 1st column in the database

No. It means: get the value from the first column of the current row in the result set, and set newID to that value.

Will Zelan wrote:
so above code which starts from newid as emp100,but newid="" and newid=null is both are different

Note that in the line above, we set newID to what we got from the database. If the value was null, then set it to "Emp100" instead.

Will Zelan wrote:
inserting values in the database newid, name and sex

That seems to insert something in the database, but since I don't know what class Database is, I can't tell you exactly how it works.

Will Zelan wrote:
if no value is entered in the database it shows the message not inserted

Yes.
 
Will Zelan
Ranch Hand
Posts: 56
Flex Python Windows Vista
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i mean we can acess parameters in previous form whic we entered in the registration page

here only one doubt why we are creating with empty string and later we are checking if newid==null
int i=0;/

here we are retrieving the max empid in the database,rs.next() means iterating the columns in the resultset(is it retrieving each column in db) and String new id=rs.getString(1) means retriving column 1 values and set to newid as string value(if iam correct pleases tell me)

now i have an idea about this,previously you told there is no value in the database means so new id will be given as emp100,once the emp100 is added in database ,further no use of above code am i corect

so adding values into database based on the registration form
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

please see the above post once which iam correct or wrong
here only one doubt why we are creating with empty string and later we are checking if newid==null
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!