Hi,
I am trying to insert 1 record of data into an Appointment table (AACAp) in Oracle 10g database. I am passing parameters from a jsp page to a servlet which then uses PreparedStatement to insert the record values, as variables, into the table. If I use literal strings and integers when I am inserting data it works fine, but if I use variables that I print to the page to ensure that they are OK before inserting them into the database, it does not work. Here is an excerpt of my code. The functional data is commented off, the non-functional data in variables is shown below uncommented. All variables have been declared as global variables. I'm using Apache Tomcat server 5.5.20.and jdk1.5
//Insert values into Appointment table AACAp in database using java.sql.PreparedStatement
sql = "INSERT INTO AACAP (sid,pdate,adate,cdate,adv
lname,advf
name,confm
ethod,stim
e," +
"etime, mobile, hphone,bsurmphone,email)VA
LUES(?,?,?
,?,?,?,?,?
,?,?,?,?,?
)";
PreparedStatement ps = con.prepareStatement(sql);
//Get current date and time using a Calendar instance
cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int date = cal.get(Calendar.DATE);
int hour = cal.get(Calendar.HOUR);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
/*
ps.setString(1, "2048017");
ps.setDate(2, new java.sql.Date(2007,10,8));
ps.setDate(3, new java.sql.Date(2007,10,9));
ps.setTimestamp(4, new java.sql.Timestamp(year,mo
nth,date,h
our,minute
,second,0)
);
ps.setString(5, "DOE");
ps.setString(6, "Jane");
ps.setString(7, "Email");
ps.setTimestamp(8, new java.sql.Timestamp(2007,10
,8,10,0,0,
0));
ps.setTimestamp(9, new java.sql.Timestamp(2007,10
,8,11,0,0,
0));
ps.setString(10, "222-111-222");
ps.setString(11, "301-322-1234");
ps.setString(12, "301-322-4321");
ps.setString(13, "jdoe@hotmail.com");
*/
//check variables to see their contents
out.println ("<p>" + pDate_yr + " " + aDate_yr + " " + pDate_mt + " " + aDate_mt + " " + pDate_dy + " " + aDate_dy + sid + " " + aData[2].trim() + " " + aData[1].trim() + " " + confirmn + " " + cPhone + " " + hPhone +
rmPhone + " " + email+"</p>");
ps.clearParameters();
ps.setString(1, sid);
ps.setDate(2, new java.sql.Date(pDate_yr,pDa
te_mt,pDat
e_dy));
ps.setDate(3, new java.sql.Date(aDate_yr,aDa
te_mt,aDat
e_dy));
ps.setTimestamp(4, new java.sql.Timestamp(year,mo
nth,date,h
our,minute
,second,0)
);
ps.setString(5, aData[2].trim());
ps.setString(6, aData[1].trim());
ps.setString(7, confirmn);
ps.setTimestamp(8, new java.sql.Timestamp(pDate_y
r,pDate_mt
,pDate_dy,
sTime_hr, 0, 0,0));
ps.setTimestamp(9, new java.sql.Timestamp(pDate_y
r,pDate_mt
,pDate_dy,
eTime_hr, 0, 0,0));
ps.setString(10, cPhone);
ps.setString(11, hPhone);
ps.setString(12, rmPhone);
ps.setString(13, email);
ps.executeUpdate();
out.println ("it's done");
marsgitte
Start Free Trial