This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes A servlet  code written to add details in database but not happening? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "A servlet  code written to add details in database but not happening?" Watch "A servlet  code written to add details in database but not happening?" New topic
Author

A servlet code written to add details in database but not happening?

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055




is there something wrong in this code??? I am not able to see it out


http://www.lifesbizzare.blogspot.com || OCJP:81%
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

TellTheDetails


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Hi Bear,

I have a Jsp page having add hyperlink.Once clicked it redirects to a JSP page where i input name email address and all and once clicked on submit button the form action attribute is set to go to prepared_statement_query servlet to add the values in the database...

I was hoping that select statement in SQL query will display new values i inputted in the jsp page.but no luck the table remains the same and is not added with any new information
Anshuman Chakraborty
Greenhorn

Joined: Oct 05, 2010
Posts: 20
Hi,

Did you check Container's log file.

Suggestion :
Try printing the values you receive from JSP.


Anshuman Chakraborty
reddy ajay
Greenhorn

Joined: Apr 21, 2011
Posts: 8
Vishal Hegde wrote:Hi Bear,

I have a Jsp page having add hyperlink.Once clicked it redirects to a JSP page where i input name email address and all and once clicked on submit button the form action attribute is set to go to prepared_statement_query servlet to add the values in the database...

I was hoping that select statement in SQL query will display new values i inputted in the jsp page.but no luck the table remains the same and is not added with any new information


did you create the database in mysql and the table,
if you did not the you need to do that first.
Also debug it using debugger and see what is happening
is it running fine or is it raising some exception.
let me know
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

reddy ajay wrote:
Vishal Hegde wrote:Hi Bear,

I have a Jsp page having add hyperlink.Once clicked it redirects to a JSP page where i input name email address and all and once clicked on submit button the form action attribute is set to go to prepared_statement_query servlet to add the values in the database...

I was hoping that select statement in SQL query will display new values i inputted in the jsp page.but no luck the table remains the same and is not added with any new information


did you create the database in mysql and the table,
if you did not the you need to do that first.
Also debug it using debugger and see what is happening
is it running fine or is it raising some exception.
let me know



Hi Ajay,

Offcourse i Created the table did you read the code for connecting my database to the table?
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Anshuman Chakraborty wrote:Hi,

Did you check Container's log file.

Suggestion :
Try printing the values you receive from JSP.



Where do i check the Log files??? Yes i did tried printing those those are successfully done
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 503
    
    4

Try loading the JDBC driver.


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Vishal Hegde wrote:
Offcourse i Created the table did you read the code for connecting my database to the table?


There is no 'of course' about it. Nothing in the code you posted creates the database or the table 'customer' or sets up the data source 'VirtualClassRoom' linking JDBC with ODBC.

There are some other weaknesses -

1) you are relying on a particular table column order which is not a good idea; you should specify the column names when using an insert.
2) your exception handling is very very poor.
3) there is no explicit commit() and there is no indication as to whether or not you are using auto-commit (I have not use the JDBC-ODBC bridge for a long time and I can't remember whether or not auto-commit matters).

As has been said - find the log files and see what they say.

Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Deepakkumar Devarajan
Ranch Hand

Joined: Apr 19, 2011
Posts: 54

Hi Vishal,
Load the JDBC driver first before coonnecting to database. You should have got "No suitable driver" as error message since you have not loaded the driver.


Regards,
Deepakkumar Devarajan
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

James Sabre wrote:
Vishal Hegde wrote:
Offcourse i Created the table did you read the code for connecting my database to the table?


There is no 'of course' about it. Nothing in the code you posted creates the database or the table 'customer' or sets up the data source 'VirtualClassRoom' linking JDBC with ODBC.

There are some other weaknesses -

1) you are relying on a particular table column order which is not a good idea; you should specify the column names when using an insert.
2) your exception handling is very very poor.
3) there is no explicit commit() and there is no indication as to whether or not you are using auto-commit (I have not use the JDBC-ODBC bridge for a long time and I can't remember whether or not auto-commit matters).

As has been said - find the log files and see what they say.


Hi James,

I have created a Customer table using select statment in MS -SQL did database connectivity going to control panel->Administratitve tools-->DataSourcesODBC) And added a user DSN named "VirtualClassRoom"

Also created a VirtualClassRoom database in MSSQL and added a table customer on it added one column to test for login authentication and its working fine... and now for insertin the value i am facing this problem
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Vishal Hegde wrote:
I have created a Customer table using select statment in MS -SQL did database connectivity going to control panel->Administratitve tools-->DataSourcesODBC) And added a user DSN named "VirtualClassRoom"

Also created a VirtualClassRoom database in MSSQL and added a table customer on it added one column to test for login authentication and its working fine... and now for insertin the value i am facing this problem


Since it's not obvious to me from the above that you did, did you add columns for user name, password, full name and login type etc? Also, did you check the servlet logs to see what they say? The logs should tell you exactly what the problem is.
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

James Sabre wrote:
Vishal Hegde wrote:
I have created a Customer table using select statment in MS -SQL did database connectivity going to control panel->Administratitve tools-->DataSourcesODBC) And added a user DSN named "VirtualClassRoom"

Also created a VirtualClassRoom database in MSSQL and added a table customer on it added one column to test for login authentication and its working fine... and now for insertin the value i am facing this problem


Since it's not obvious to me from the above that you did, did you add columns for user name, password, full name and login type etc? Also, did you check the servlet logs to see what they say? The logs should tell you exactly what the problem is.


Yes i did those ,where should i check the logs? I am using netbeans?
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Google is wonderful - http://blogs.oracle.com/NetBeansSupport/entry/tomcat_log_files
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A servlet code written to add details in database but not happening?
 
Similar Threads
Login code problem
org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 8
Not able to add up values in the table of a database
Not able to add values in a database
not able to insert values in ms access database