Forums Register Login

problem with insertion..

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Hi Jyotsana,
Your INSERT statement is wrong. This is a JDBC problem (or more specifically, an SQL problem), rather than a JSP problem. In SQL, there are no WHERE clauses in INSERT statements. So just remove the WHERE clause from your INSERT statement, as in:

Good Luck,
Avi.
+Pie Number of slices to send: Send
Hi Avi..
thanks for replying..
bt i need to check the insertion against the username...only if the user has logged in, should he be able to insert his paper..
i need to maintain the session..
and the tables i created for this purpose, have user_login also as the column like paper table has user_login, paper_title etc. as the columns..
and i have given a not null constraint in the user_login..
so if i remove the where clause.. it gives an exception.. can't insert null value to user_login..insert fails
any guidance.. in this..iam fairly new to jsp ..
thanks
[ November 25, 2003: Message edited by: jyotsana dang ]
+Pie Number of slices to send: Send
Hi..
If the user_login already has some value, you only need UPDATE Statement the table, else you insert everything into the Paper table, as pointed by Avi, there can never be a where in INSERT Statements.
For checking wether the user has already logged in, you just check it out with the session.
hth
MB
+Pie Number of slices to send: Send
Moving to the JDBC forum.
bear
+Pie Number of slices to send: Send
thanks everyone..
bt the problem still remains.
.. i made changes to the insert stmt..
bt ..
in this page i have 3 textfields .. paper_title,authors, year, citation..
whatever value i give in the paper_title .. it gives an error in the same..
if i give "one" as the value..
it shows the error as
:
the value of paper_title ne
the value of co is:two
the value of citation is:three
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: In
correct syntax near 'one'.

here's the code again:

<%@ 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="";the value of paper is ne

String xy=(String)session.getAttribute("y");
if(xy==null)
xy="jasu";
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();
out.println("insert into Papers(user_login,paper_title,co_authors,year,citation) values('"+xy+"'"+paper_title+"','"+co_authors+"',"+year+",'"+citation+"')");

int i=stmt.executeUpdate("insert into Papers(user_login,paper_title,co_authors,year,citation) values('"+xy+"'"+paper_title+"','"+co_authors+"',"+year+",'"+citation+"')");
System.out.println("the value of:" +i);
stmt.close();

con.close();
}
catch(Exception e)
{
System.out.println(e);

}

%>
This parrot is no more. It has ceased to be. Now it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1215 times.
Similar Threads
can anyone solve this
data in table getting overridden?
not able to insert a null value in the database
login
data in table getting overridden?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:50:40.