i am using jsp to create web site. How can i insert data into database but do not have text box in the web site. i want to have data automatically show in the database without having people key in data from web site. the purpose for doing this is i want to generate default answer for every member.
tk_Sajesh
April 30th, 2004, 12:33 AM
what data u r expecting to store in the Database?
jilshi
April 30th, 2004, 02:23 AM
i want to generate answer for the user. every user will have different answer. their answer will be what is their lot no. i already generate question for them which is "what is my lot no?"
i attach part of my code. Every data in the code are fine except "answer" part because data that insert into database was wrong. data in database under "answer" field all has same data.
<% if (session.getAttribute("user_name") != null) {
Random randGen = new Random(System.currentTimeMillis());
bufUserID = new StringBuffer();
bufPassword = new StringBuffer();
//bufQuestion = new StringBuffer();
//bufAnswer = new StringBuffer();
Can u just explain the workflow!!
Im bit confused..
Is it something like this, a user if he forgets the password, click on the Forgot password link, then will be prompted 2 enter the answer for his password question.
Once he enters the right answer, he will be supplied with the password..
jilshi
April 30th, 2004, 02:39 AM
actually this page is creted not for user to user. i create this page just for administrator to use. After administrator execute this page, the function will provide default id name, password, question and answer for user. now all data are display correctly in database except "answer". data in database under "answer" field has wrong data.
tk_Sajesh
April 30th, 2004, 03:49 AM
Picture In my mind
+-+-+-+-+-+-+-+-+
Administrator will create the user.
UserId, Password, Password Question & Answer will be automatically generated & stored in the database.
Only the data for the "answer" is wrongly inserted in the database,then the problem surely will be in the insert statement which u have executed.
Inorder 2 c whether the query generated is correct, just output the query & c whether it is correct or not.
jilshi
April 30th, 2004, 03:58 AM
yes, i know what you mean. do u have any idea to correct my mistake.
i already try out.print() but still can't find the answer
tk_Sajesh
April 30th, 2004, 04:15 AM
if (rset_e.next()) {
answer = rset_e.getString("fs_lot_no");
out.print(answer);
session.setAttribute("answer", answer);
}
Is The answer getting displayed in the webpage correct?
answer = answer;
out.print(answer);
Y Is the answer variable getting reassigned?
is the answer getting printed correct?
is that the data in the table is getting swapped or u r getting a different data?
jilshi
April 30th, 2004, 04:40 AM
VERY WEIRD. the answer don't display anything on the screen after out.print()
However there is data insert into database. all the value under "answer" in database has the same value. what i need is different value according to the relevevant data.
tk_Sajesh
April 30th, 2004, 04:52 AM
can u send the entire code & the database script coz I need 2 execute & c the result..
jilshi
April 30th, 2004, 04:55 AM
Below is the full coding. thanks for your advice
<%@page import = "java.util.Random,java.lang.*,java.sql.*,java.util.*,java.awt.*,java.io.*,
java.sql.Connection,java.sql.DriverManager,java.sql.SQLException,java.lang.String.*,
java.text.SimpleDateFormat" %>
<%//@page errorPage = "handle_errors.jsp"%>
<% response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server %>
<% // VALIDATE USER IS FROM AUTHORIZED/CORRECT PAGE
if(session.getAttribute("user_name")==null)
response.sendRedirect(response.encodeRedirectUrl("relogin.jsp"));
else { %>
<% String serv = (String)session.getAttribute("server");
String db = (String)session.getAttribute("database");
<html>
<head>
<title>Ramdom Generate Owner's Login Name and Password</title>
<link rel="stylesheet" href="facilities.css">
<script language="Javascript">
var this_weekday_name_array = new Array
(
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
)
var this_month_name_array = new Array
(
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
)
var this_date_timestamp=new Date()
var this_weekday = this_date_timestamp.getDay()
var this_date = this_date_timestamp.getDate()
var this_month = this_date_timestamp.getMonth()
var this_year = this_date_timestamp.getYear()
if (this_year < 1000)
this_year+= 1900;
if (this_year==101)
this_year=2001;
var this_week_string = this_weekday_name_array[this_weekday]
var this_date_string = this_date + " " + this_month_name_array[this_month] + " " + this_year
Random randGen = new Random(System.currentTimeMillis());
bufUserID = new StringBuffer();
bufPassword = new StringBuffer();
//bufQuestion = new StringBuffer();
//bufAnswer = new StringBuffer();
//out.println("<br>Access no="+accessNo+"~~~Random User ID="+userID+"~~~Random Password="+password+"~~~Total Record In Database="+totalRecordInDatabase+"\n");
//out.println("<br>Random User ID = "+userID);
//out.println("<br>Random Password = "+password);
//out.println("<br>Total Record In Database = "+totalRecordInDatabase+"\n");
<h1> </h1>
<h1> </h1>
<META HTTP-EQUIV="refresh" CONTENT="2; URL=maintenance_main.jsp">
<h1 align="center"><font color="#000099">Default Login Name and Password have been generated for owners.</font></h1>