Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 04-30-2004, 12:17 AM   #1 (permalink)
 
Newb Techie

Join Date: Feb 2004

Posts: 15

jilshi

Unhappy insert data into database

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.
jilshi is offline  
Old 04-30-2004, 12:35 AM   #2 (permalink)
 
Banned

Join Date: Jan 2004

Posts: 471

subdivizion

Default

hmm how would the data go in the databbase? what type of database are you talking about? better yet, what is it that you are trying to do?
subdivizion is offline  
Old 04-30-2004, 01:07 AM   #3 (permalink)
 
Monster Techie

Join Date: Jul 2003

Posts: 1,179

Emily is on a distinguished road

Send a message via AIM to Emily
Default

Quote:
hmm how would the data go in the databbase? what type of database are you talking about? better yet, what is it that you are trying to do?
Ditto.. and also, when you insert data from a textbox into a database, do you put it into an intermediate variable first? If so, can you just substitute a value for that variable? Or can you use a < input type="hidden" name="name" value="value> for your purposes?
__________________
<a href=\"http://www.upstark.com\">www.upstark.com</a>
Emily is offline  
Old 04-30-2004, 02:24 AM   #4 (permalink)
 
Newb Techie

Join Date: Feb 2004

Posts: 15

jilshi

Red face

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) {

String uName = (String)session.getValue("user_name");
String sql_1 = "SELECT es_iden, es_access_no "+
"FROM esaccs "+
"WHERE es_usr_id='"+uName+"' ";
Statement stmt_1 = conn.createStatement();
ResultSet rset_1 = stmt_1.executeQuery(sql_1);
while (rset_1.next()) {
ident = rset_1.getString("es_iden");
accNo = rset_1.getString("es_access_no");
//answer = rset_1.getString("es_ans");
}

String sql_2 = "SELECT fs_email_addr "+
"FROM fcrsdt "+
"WHERE fs_access_no = '"+accNo+"' ";
Statement stmt_2 = conn.createStatement();
ResultSet rset_2 = stmt_2.executeQuery(sql_2);
while (rset_2.next()) {
emailAddr = rset_2.getString("fs_email_addr");
out.print(emailAddr);
//lotno = rset_2.getString("fs_lot_no");
//out.print(lotno);
}
String select_e = "SELECT fs_lot_no "+
"FROM fcrsdt "+
"WHERE fs_lot_no = '"+answer+"' ";
Statement stmt_e = conn.createStatement();
ResultSet rset_e = stmt_e.executeQuery(select_e);
if (rset_e.next()) {
answer = rset_e.getString("fs_lot_no");
out.print(answer);
session.setAttribute("answer", answer);
}
}

try {
int totalRecordInDatabase = 0;
int intAccsNo = 1;
String sql = "SELECT count(*) as recordCount "+
"FROM fcrsdt "+
"WHERE fs_cat_typ ='O' ";
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
totalRecordInDatabase = rset.getInt("recordCount");
}
int iZero, iNine, iA, iZ, randNum;
StringBuffer bufUserID;
StringBuffer bufPassword;
//StringBuffer bufQuestion;
StringBuffer bufAnswer;

String strAccessNo="",accessNo,userID,password, question;

iZero = '0';
iNine = '9';
iA = 'A';
iZ = 'Z';

Random randGen = new Random(System.currentTimeMillis());
bufUserID = new StringBuffer();
bufPassword = new StringBuffer();
//bufQuestion = new StringBuffer();
//bufAnswer = new StringBuffer();

while (intAccsNo <= totalRecordInDatabase) {
strAccessNo = String.valueOf(intAccsNo);
accessNo = strAccessNo+".00";

for (int i = 0; i< 6; i++) {
randNum = randGen.nextInt(iZ);
while (!(randNum >= iZero && randNum <= iNine) &&!(randNum >= iA && randNum <= iZ)) {
randNum = randGen.nextInt(iZ);
}
char c = (char)randNum ;
bufUserID.append(c);
}//for
for (int ii= 0; ii< 6; ii++) {
randNum = randGen.nextInt(iZ);
while (!(randNum >= iZero && randNum <= iNine) &&!(randNum >= iA && randNum <= iZ)){
randNum = randGen.nextInt(iZ);
}
char c = (char)randNum ;
bufPassword.append(c);
}//for

userID = bufUserID.toString();
password = bufPassword.toString();
question = "What is my lot no?";
answer = answer;
out.print(answer);

bufUserID.delete(0,7);
bufPassword.delete(0,7);
//bufQuestion.delete(0,7);
//bufAnswer.delete(0,7);
String sql_insert ="INSERT INTO esaccs(es_access_no,es_usr_id,es_password,es_sts,e
s_iden,es_question,es_ans) "+
"VALUES(?,?,?,?,?,?,?)";
PreparedStatement ps_1 = conn.prepareStatement(sql_insert);
ps_1.setString(1,accessNo);
ps_1.setString(2,userID);
ps_1.setString(3,password);
ps_1.setString(4,"A");
ps_1.setString(5,"O");
ps_1.setString(6,question);
ps_1.setString(7,answer);
ps_1.executeUpdate();
ps_1.close();
jilshi is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On