This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes jsp postgress connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jsp postgress connection" Watch "jsp postgress connection" New topic
Author

jsp postgress connection

ankur mawandia
Greenhorn

Joined: Jan 10, 2011
Posts: 12

i am trying to connect a jsp page to the postgres db

i have written a html form and i am trying to post the data to the database

i am reciving an error

the jsp page is





the error says
org.apache.jasper.JasperException: javax.servlet.ServletException: org.postgresql.util.PSQLException: ERROR: syntax error at or near "["
Position: 18

ng


thnx in advance
also i am still new so please point out the errors i am making

thnx






may the force be with you
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Why is this code in a JSP rather than properly in a servlet?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ankur mawandia
Greenhorn

Joined: Jan 10, 2011
Posts: 12

i just want to check wether my postgres driver is properly installed or not.....and wether i can conncet to the database or not

Sunny Bhandari
Ranch Hand

Joined: Dec 06, 2010
Posts: 448

I am not familiar with postgress but will advise to debug the code to check that the source of error is the INSERT statement.

You can also write a java class for that...


Java Experience
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Do it in a Java class like a servlet. Doing this in a JSP is a poor practice and problematic.

Compiling a Java class is likely to give you better error messages as well.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

Ankur,
Welcome to CodeRanch!

I agree that it would be better to move this code out of the JSP. As for your error, it looks like you are connecting to the database and getting an error running the insert. There aren't braces around the column names in an insert. You can try running the SQL statement at the postgres command line to make sure it works.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
ankur mawandia
Greenhorn

Joined: Jan 10, 2011
Posts: 12

thank you so much bear and jeanne..for your valueble sujjestion

the problems was in the query as you said
can you tell me how to set this properly in a servelet

Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3826

...can you tell me how to set this properly in a servelet

Modern JSPs should not contain any Java code (if possible even the old code should not). Move them to controller/model classes appropriately.

If you are new to web development you may want to look at the MVC pattern.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp postgress connection