insert into database
String first_name = request.getParameter("firstName");
i m extracting the informaion from atextfield and want to insert into database
int queryinsert = stmt.executeUpdate("INSERT INTO customer (cust_first_name)VALUES(\""+first_name )+";");
i m getting error here,plz tell me the right way
[422 byte] By [
anya_aaa] at [2007-11-27 4:00:30]

First off what error are you getting?PS
cannot convert from int to string
Do you have a stacktrace?
ps = con.prepareStatement("INSERT INTO customer (cust_first_name) VALUES (?)"); ps.setString(1, firstName);ps.executeUpdate();
what type of ps is?is it int ,string , im getting errors with all these can't converst ps to string/int.
> what type of ps is?
Figure it out. It's the result of a method call on Connection. Look at Connection's docs to see what that method returns.
> is it int ,string , im getting
> errors with all these can't converst ps to string/int.
Start here. Learn basic Java.
http://java.sun.com/docs/books/tutorial/java/index.html
Then learn JDBC.
http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/JDBC20.html
oh pleaaaaaaaassse i m running out of time it is just this last aprt left, what is ps?plz i have done so much in my project,and this last part im getting stuck,plz understand that i m a university student and we didnot have proper teachers to guide us.we learnt all on our own through internet.pleeeeeassssse help meeeeeeeee.
now i m getting this it doesn't tell what is wrong?
org.apache.jasper.JasperException: An exception occurred processing JSP page /form.jsp at line 101
98:
99: PreparedStatement ps = conn.prepareStatement("INSERT INTO customer (cust_first_name) VALUES (?)");
100: ps.setString(1, "first_name");
101: ps.executeUpdate();
You've been too interested in getting answers so you can turn your assignment in and not interested enough in understanding what's going on. I don't have the time or interest to deal with that. Good luck.
thx for ur symapathertic answer,true if i had time i would have surely tried to learn anyways i have to learn for my exams just coming in 2 weeks from now.but tomorrow we have to submit our projects,
i will yet again say that ppl shouldn't comment like this because they don't know what is going on exactly in others' ppl life.
if u had known in under what conditions i have made progress,u would have been very surprised.
anyway i can't tell my whole story of sufferings in here,
but 1 think i surely can say is that i love Java and i wouldn't have taken this course, if i didnot know what i m going to go thru.
> i will yet again say that ppl shouldn't comment like
> this because they don't know what is going on exactly
> in others' ppl life.
And I will say that this is a public, unmoderated, free forum, so you don't get to pick what people say.
I will also say that your other circumstances have no bearing on my opinion or my comments.
The PreparedStatement and its associated calls DO NOT go in the JSP ... You will want a servlet which will in turn call a bean that will execute the call to the DB.PS
> thx for ur symapathertic answer,true if i had time i
> would have surely tried to learn anyways i have to
> learn for my exams just coming in 2 weeks from
> now.but tomorrow we have to submit our projects,
> i will yet again say that ppl shouldn't comment like
> this because they don't know what is going on exactly
> in others' ppl life.
> if u had known in under what conditions i have made
> progress,u would have been very surprised.
> anyway i can't tell my whole story of sufferings in
> here,
> but 1 think i surely can say is that i love Java and
> i wouldn't have taken this course, if i didnot know
> what i m going to go thru.
The following is not intended to be mean, it is however intended to be brutally honest.
1. The world does not, will not, care about you, or your problems or the obstacles that are in your way.
2. In the development world the only human resource you will often have is yourself.
3. You will often have to research, understand and internalize wholly new technologies and design patterns and any manner of topics related to the development effort in a very short amount of time.
4. Whining about it will not help you, nor will it endear you or your plight to people, nor will it make anyone more inclined to want to help.
It's part of the job. Deal with it now or find something else to do.
Most of us here developed our expertise on our own through research, dedication and hard work. Most of us will have little patience for people who are unwilling to put for the effort to learn not just how a thing can be done but why it should or should not be done and when it should or should not be done.
PS.
thanx for the big advice,that is y i never told my story, ofcourse i have to deal and solve my problems.
now back to my question. ok i don't have a bean, so i guess i can't use prepared statement.
y can 't i use this?
String queryinsert = stmt.executeUpdate("INSERT INTO customer (cust_first_name)VALUES(\""+first_name+" "\")" +";");
y this is not working.
any other logic is there than to create a bean?
> now back to my question. ok i don't have a bean, so i> guess i can't use prepared statement.You can and should use PreparedStatement.
jverda at 2007-7-21 21:00:53 >

sorry this statement is wrong
i m getting this error
An error occurred at line: 103 in the jsp file: /form.jsp
The method executeUpdate(String, int) in the type Statement is not applicable for the arguments (String, String)
100:
101:
102:
103: String queryinsert = stmt.executeUpdate("INSERT INTO customer (cust_first_name)VALUES("first_name" )" +";");
"The PreparedStatement and its associated calls DO NOT go in the JSP ... You will want a servlet which will in turn call a bean that will execute the call to the DB."this advice is given in this threadas i understand that i have to create a bean.
> sorry this statement is wrong
>
> i m getting this error
> An error occurred at line: 103 in the jsp file:
> /form.jsp
> The method executeUpdate(String, int) in the type
> Statement is not applicable for the arguments
> (String, String)
> 100:
> 101:
> 102:
> 103: String queryinsert = stmt.executeUpdate("INSERT
> INTO customer (cust_first_name)VALUES("first_name"
> )" +";");
The error message is telling you exactly what's wrong. But rather than try to fix you incorrect approach to satisfy the compiler, why not take the correct approach and use PreparedStatement?
jverda at 2007-7-21 21:00:53 >

alright i ll follow prepared statement but that also doesn't work, i don't have the time to create a bean. so without bean if it works fine,i ll do it.tell me the way because i get this error.with ps.
org.apache.jasper.JasperException: An exception occurred processing JSP page /form.jsp at line 10299: 100: PreparedStatement ps = conn.prepareStatement("INSERT INTO customer (cust_first_name) VALUES (?)"); 101: ps.setString(1, "firstName");102:
Has anyone commented on "JDBC in a JSP"?
1) There must be more info on the error somewhere. Probably a stack trace in a log file. If not, you need to configure your container to log more verbosely.
2) Do you not see one huge, obivous way in which what this is doing is very different from what your original code did? Did you try to understand this code before using it? It's an example, not something to just copy/paste. It's up to you to analyze, understand, and adapt it.
jverda at 2007-7-21 21:00:54 >

> Has anyone commented on "JDBC in a JSP"?I believe that's been mentioned. I assume that fixing that glaring error is beyond the OP's ability at the moment. Certainly it's beyond my time and patience to explain.
jverda at 2007-7-21 21:00:55 >

> > thx for ur symapathertic answer,true if i had time
> i
> > would have surely tried to learn anyways i have to
> > learn for my exams just coming in 2 weeks from
> > now.but tomorrow we have to submit our projects,
> > i will yet again say that ppl shouldn't comment
> like
> > this because they don't know what is going on
> exactly
> > in others' ppl life.
Correct me if I am wrong you have 190 posts to this point, so you have most likely been working with java for quite some time as well as been on these forms for quite some time. Learn to reasearch and manage time better.
> 4. Whining about it will not help you, nor will it
> endear you or your plight to people, nor will it make
> anyone more inclined to want to help.
You forgot wasting time you could have been using to solve your current problem.
thx for spending ur time.
yes i did open my book and hunted for prepared statement and they have just mentioned one proogram the usage of the ps and that is also a java program.
they told all those gr8 advantages.
hmmm i have still doubts
in this
ps.setString(1, "firstName");///in place of first_name exactly do we have to use a variable name or the name of the textbox,in my book they just put directly the value.
> thx for spending ur time.
> yes i did open my book and hunted for prepared
> statement and they have just mentioned one proogram
> the usage of the ps and that is also a java program.
> they told all those gr8 advantages.
> hmmm i have still doubts
> in this
Read the javadoc. The argument is a String.
@Op. Have you ever seen a method that only can take a string literal and not a string reference/variable?
Kaj
kajbja at 2007-7-21 21:00:57 >

can any1 explain me y the error is onps.executeUpdate();y it is not executing?/
> can any1 explain me y the error is on> ps.executeUpdate();> > it is not executing?/Because you haven't done any reading to understand why.
> can any1 explain me y the error is on
> ps.executeUpdate();
>
> it is not executing?/
I have a guess, but you need to find the log that will have the stack trace.
Again, look at your code in your first post. Closely.
Then look at the code you're trying to use now. Closely.
What, exactly, will your original code insert?
What, exactly, will your current code try to insert?
jverda at 2007-7-21 21:00:58 >

Also, if you're having such a hard time debugging this JDBC stuff in your JSP (which is a bad place to put JDBC stuff--or any Java code), then you should write a tiny little standalone program that just does that insert and get that working first.
jverda at 2007-7-21 21:01:03 >

well can u give me a link,because write now i m doing other project also.
> well can u give me a link,
> because write now i m doing other project also.
A link to what? I already gave you two links.
And really, I'm giving you an important clue. You need to pay more attention and be more careful and detail oriented in your debugging. Answer the questions I asked a couple of posts ago.
jverda at 2007-7-21 21:01:03 >

Have you looked to see what, if anything, *IS* in that table?
jverda at 2007-7-21 21:01:03 >

ok sorryi checked ur links it didn't give me what i wantedi wnat to know y this not working? ps.executeUpdate();i m opening so many sites on ps ,they r just talking on its advantages,i get the big ideaaaaaa.
> ok sorry
> i checked ur links it didn't give me what i wanted
> i wnat to know y this not working?
> ps.executeUpdate();
> i m opening so many sites on ps ,they r just talking
> on its advantages,i get the big ideaaaaaa.
GAH!
IN WHAT WAY IS IT NOT WORKING?
HAVE YOU BOTHERED TO FIND THE LOG FILE WHERE THE WHOLE STACK TRACE WILL BE SO YOU CAN GET MORE INFORMATION?
HAVE YOU LOOKED TO SEE WHAT, IF ANYTHING IS IN THAT TABLE?
WHAT WOULD YOUR INITIAL CODE INSERT IF IT WORKED?
WHAT WOULD YOUR LATEST CODE INSERT IF IT WORKED?
WHY WON'T YOU TRY A SIMPLE STANDALONE PROGRAM?
You have to do some digging and some thinking about what's supposed to happen and what could be going wrong.
You have to look at more than just one line of code and one vague error message.
There are a million things that could be wrong. You have to engage your brain and do some work to narrow down the possibilities.
You can't just provide a tiny bit of vague information and then ask people to solve your problem. You're totally ignoring my hints and suggestions and questions, so screw it. I'm not wasting any more time on this.
jverda at 2007-7-21 21:01:03 >

> GAH!Lol. A bit frustrated? :)
kajbja at 2007-7-21 21:01:03 >

> > GAH!> > Lol. A bit frustrated? :)Jebus.Have you been reading this trainwreck?
jverda at 2007-7-21 21:01:03 >

> > > GAH!> > > > Lol. A bit frustrated? :)> > Jebus.> > Have you been reading this trainwreck?Can you avoid looking at an accident? :)I'm reading but I don't want to be part of the "rescue crew" :)
kajbja at 2007-7-21 21:01:03 >

[url #" style="display: block; background-image: url(' http://vcard.homer-simpson.de/images/homer/pic18.jpg'); width: 343px; height: 398px] [/url]
the table is empty.and i want the table to be empty.that is y initially i m using insert statement.
> the table is empty.
> and i want the table to be empty.
> that is y initially i m using insert statement.
I know why you're using insert. If you feel the need to tell me why, you're completely missing the point. I'm not trying to attack or insult you, but you really don't seem to be in the right mindset to debug this.
And you STILL haven't addressed several things I suggested.
jverda at 2007-7-21 21:01:03 >

try inserting single qoutes into you insert statment and see,i think it should work
> try inserting single qoutes into you insert statment> and see,i think it should workThat's the wrong solution.
jverda at 2007-7-21 21:01:03 >

> thx for spending ur time.
> yes i did open my book and hunted for prepared
> statement and they have just mentioned one proogram
> the usage of the ps and that is also a java program.
> they told all those gr8 advantages.
> hmmm i have still doubts
> in this
> > ps.setString(1, "firstName");///in place of
> first_name exactly do we have to use a variable name
> or the name of the textbox,in my book they just put
> directly the value.
>
Maybe I'm late to this...an I generally look away from train wrecks...but.
String s="firstName";
ps.setString(1,s);
and
ps.setString(1,"firstName");
These have, you understand, an identical effect?
Message was edited by:
xiarcel
Hi
int queryinsert = stmt.executeUpdate("INSERT INTO customer (cust_first_name)VALUES("+first_name+" )");
Guess... the above line will work for you.
Replace the line with the line pasted by me in your code and try.
if still facing issues... paste the entire code(or the part of it) if possible.. so tht we can figure out what was the prob.
But in real time applications, generally we use PreparedStament, rather Statement.
> Hi
>
> int queryinsert = stmt.executeUpdate("INSERT INTO
> customer (cust_first_name)VALUES("+first_name+" )");
>
>
> Guess... the above line will work for you.
> Replace the line with the line pasted by me in your
> code and try.
> if still facing issues... paste the entire code(or
> the part of it) if possible.. so tht we can figure
> out what was the prob.
>
> But in real time applications, generally we use
> PreparedStament, rather Statement.
Any particular reason you decided to ignore all the other answers that have been given and just paste a mixture of bad advice and repeats of what she's already been told?
jverda at 2007-7-21 21:01:08 >

> Hi
>
> int queryinsert = stmt.executeUpdate("INSERT INTO
> customer (cust_first_name)VALUES("+first_name+" )");
>
>
> Guess... the above line will work for you.
> Replace the line with the line pasted by me in your
> code and try.
If the future make an attempt to not post solutions that not only demonstrate bad form but are in fact just simply wrong.