Advertisement

10.09.2007 at 03:38PM PDT, ID: 22882846
[x]
Attachment Details

Cannot insert record into Oracle database table when PreparedStatement is used with variables

Asked by marsgitte in Apache Tomcat Application Server, Oracle 10.x, Java Servlets

Tags: oracle, insert, table, database, record

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,advlname,advfname,confmethod,stime," +
          "etime, mobile, hphone,bsurmphone,email)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
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,month,date,hour,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,pDate_mt,pDate_dy));
ps.setDate(3, new java.sql.Date(aDate_yr,aDate_mt,aDate_dy));
ps.setTimestamp(4, new java.sql.Timestamp(year,month,date,hour,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_yr,pDate_mt,pDate_dy,sTime_hr, 0, 0,0));
ps.setTimestamp(9, new java.sql.Timestamp(pDate_yr,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");  

marsgitteStart Free Trial
[+][-]10.09.2007 at 03:59PM PDT, ID: 20045236

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.09.2007 at 04:06PM PDT, ID: 20045265

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.09.2007 at 04:13PM PDT, ID: 20045292

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.09.2007 at 04:32PM PDT, ID: 20045369

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.09.2007 at 04:45PM PDT, ID: 20045429

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.09.2007 at 07:19PM PDT, ID: 20045996

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Apache Tomcat Application Server, Oracle 10.x, Java Servlets
Tags: oracle, insert, table, database, record
Sign Up Now!
Solution Provided By: sdstuber
Participating Experts: 1
Solution Grade: B
 
 
[+][-]10.15.2007 at 02:42PM PDT, ID: 20081732

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.17.2007 at 01:53PM PDT, ID: 20096959

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628