943,945 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 4697
  • JSP RSS
Feb 8th, 2007
0

problem in inserting data in msaccess

Expand Post »
<%@ page language = "java" import = "java.sql.*" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.text.*" %>
<%
String username,passw,passw1,compnam,tinn;
username= request.getParameter("username");
passw = request.getParameter("pwd");
passw1 = request.getParameter("pwd1");
compnam = request.getParameter("compname");
tinn=request.getParameter("TIN");


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String st = "jdbc:odbc:loginval";
Connection cn = DriverManager.getConnection(st," "," ");
Statement stmt = cn.createStatement();
String sql = "insert into register " ;
sql +="(username,pwd,pwd1,compname,TIN)";
sql += " values ('";
sql += username ;
sql += "','";
sql += passw;
sql += "','";
sql += passw1;
sql += "','" ;
sql += compnam ;
sql += "','" ;
sql += tinn;
sql += "')";
int val = stmt.executeUpdate(sql);
cn.close();
if(val==1)
{
%>
<jsp:forward page = "success.html"/>
<%
}
%>
-----------------------------------------------------------------------------------------------
this is my code, i am not able to insert any values in to my table thru this code, when i submit for the first time null values are stored in the table i mean "null" is getting displayed in the table.
when i submit for the second time then the server throws an error "general error"
some one help me plz
thanks in advance
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kiranme is offline Offline
1 posts
since Jan 2007
Feb 8th, 2007
0

Re: problem in inserting data in msaccess

YUGH!!!!!!

You don't properly close your database resource, you use String concatenation all over the place, you have massive scriptlets in a JSP, you place business logic in a JSP, you don't use code tags.

And you don't seem to understand what you're doing.

Of course it stores all null values when you call the page as those request parameters won't have been set.
And most likely the error on subsequent calls is a primary key violation from trying to insert another null value (I guess you declared username to be unique).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Communication Link Failure Error
Next Thread in JSP Forum Timeline: back end of the "< jsp:setProperty" tag





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC