iam not being able to insert the values in database..
here is the code for insertion:
<%@ page language="java" import="java.sql.*,java.io.*" %>
<%
Connection con=null;
java.sql.Statement stmt=null;
String paper_title="";
String co_authors="";
int year=0;
String citation="";
String username="";
String xy=(String)session.getAttribute("y");
if(xy==null)
xy="jasu";
username= request.getParameter("username");
paper_title=request.getParameter("paper_title");
co_authors=request.getParameter("co_authors");
year=Integer.parseInt(request.getParameter("year"));
citation=request.getParameter("citation");
out.println(username);
System.out.println("the value of paper is:"+paper_title);
System.out.println("the value of co is:"+co_authors);
System.out.println("the value of citation is:"+citation);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:mech_iit");
stmt=con.createStatement();
int i=stmt.executeUpdate("insert into Papers(paper_title,co_authors,year,citation) values('"+paper_title+"','"+co_authors+"',"+year+",'"+citation+"') where user_login='"+username+"')");
System.out.println("the value of:" +i);
stmt.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
%>
inthis when the user logs in he can insert his papers.. bt in the tomcat window.. iam able to see the values which the user inserts bt not the username..
and moreover it gives a sqlexception that
incorrect syntax near the keyword 'where'
.. means i guess session is nt being maintained properly..
pls help..
thanks
here is the code for insertion:
<%@ page language="java" import="java.sql.*,java.io.*" %>
<%
Connection con=null;
java.sql.Statement stmt=null;
String paper_title="";
String co_authors="";
int year=0;
String citation="";
String username="";
String xy=(String)session.getAttribute("y");
if(xy==null)
xy="jasu";
username= request.getParameter("username");
paper_title=request.getParameter("paper_title");
co_authors=request.getParameter("co_authors");
year=Integer.parseInt(request.getParameter("year"));
citation=request.getParameter("citation");
out.println(username);
System.out.println("the value of paper is:"+paper_title);
System.out.println("the value of co is:"+co_authors);
System.out.println("the value of citation is:"+citation);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:mech_iit");
stmt=con.createStatement();
int i=stmt.executeUpdate("insert into Papers(paper_title,co_authors,year,citation) values('"+paper_title+"','"+co_authors+"',"+year+",'"+citation+"') where user_login='"+username+"')");
System.out.println("the value of:" +i);
stmt.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
%>
inthis when the user logs in he can insert his papers.. bt in the tomcat window.. iam able to see the values which the user inserts bt not the username..
and moreover it gives a sqlexception that
incorrect syntax near the keyword 'where'
.. means i guess session is nt being maintained properly..
pls help..
thanks