Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

this is wot my codes like

 
payal kapadia
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my codes something like this.

<html>....
//script
function subb()
{


document.f1.submit();
<%
String id1=(request.getParameter("gpd"));
System.out.println(id1);
insbn.setsc_details(id1);
insbn.retdb();
%>
}
//script ends

<form>

<input type="text" name="gpd">
<input type="button" name="ss" value="submit" >//onclick goes to subb

</form></html>

//the bean file goes like this.

public class insretgp
{

public String sc;

public String getsc_details()
{
return sc;
}

public void setsc_details(String c)
{
sc=c;
System.out.println(sc);
}

public void retdb()
{
String sname=getsc_details();
String nn="null";
try
{


Context initCtx=new InitialContext();
if(initCtx == null)
throw new Exception("Boom - no Context");
Context envCtx=(Context) initCtx.lookup("java:comp/env");
DataSource ds=(DataSource) envCtx.lookup("jdbc/myoracle");
Connection conn=ds.getConnection();
Statement stmt2=conn.createStatement();

String query2="insert into gp" + "(ss)"+"values" +"('"+sname+"')";
String query3="delete from gp where (ss='"+nn+"')";
Statement stmt3=conn.createStatement();
stmt2.executeUpdate(query2);
stmt3.executeUpdate(query3);
stmt2.close();
stmt3.close();
conn.close();
}
catch(SQLException e)
{
System.out.println("Exception occured in class:insretgp" +e.toString());
}
catch(Exception er)
{
System.out.println("Exception occured in class:insretgp" +er.toString());
}}}
 
Vijay Sharma
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi payal,
First thing you should learn variable Naming skills.Because you had taken gbd,nn this kind of variable,so it makes understanding code worse.Anyway i had reviewed your code.There you had taken one variable as nn and assign it a string value null.Again just check your query.Also do one thing first remove all the statement of context lookup and createStatement from the retdb() function.Put these statement in the class outside the function.Then it becomes more clear.I think from somewhere you are inserting the value of "nn" variable.That's why it is creating the problems.Just do these things and check whether the code is working or not,and tell me.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll also get a lot more people to look at your code and help you out if you wrap it in code tags to preserve indenting.

There is a UBB CODE button on the page that makes this very easy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic