| | |
problem in inserting data in msaccess
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2007
Posts: 1
Reputation:
Solved Threads: 0
<%@ 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
<%@ 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
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).
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).
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- how to insert data into the database in vb.net using textfields. (VB.NET)
- Problem with retrieving data from access 2003 (Visual Basic 4 / 5 / 6)
- VB.Net: Problem Retrieve data from ListView (VB.NET)
- Problem inserting data into database (JSP)
- Help with binary search tree insertion (C++)
Other Threads in the JSP Forum
- Previous Thread: Communication Link Failure Error
- Next Thread: back end of the "< jsp:setProperty" tag
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






