0

i am having some connectivvity issues i am using postgres 9.0 sql db

i have installed a dns localhost using the postgres sql driver

also i have the jdbc jar files in the lib dir of the tomcat

my code is

<%@ page language="java" import="java.sql.*" %>

	 <%
	  
 	    Class.forName("org.postgresql.Driver");
 	    	    Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/sample", "postgres", "ankur");


            Statement stmt = conn.createStatement();
           

      
      
 String StrUser = request.getParameter("username");
 String Age = request.getParameter("age"); 
  
stmt.executeUpdate("INSERT INTO tab1 VALUES ('ankur',21);" );
stmt.close();
     conn.close();

            %>

the error generated is


avax.servlet.ServletException: org.postgresql.util.PSQLException: ERROR: syntax error at or near "["
Position: 18

Edited by ankurmawanda: n/a

2
Contributors
8
Replies
10
Views
6 Years
Discussion Span
Last Post by masijade
1

This is not the code you're running considering the message

syntax error at or near "["

Edit: Not that you should be using scriptlets at all. And also most definately not be loading the driver and getting a new connection with every page load, use a pool.

Edited by masijade: n/a

0

sorry for my bad programming practise......i am still a learner
i only intend to check the connection using this page.....


http://i55.tinypic.com/v42ie1.jpg

pgs_check.jsp

<HTML>
<Head><title>postgres connection check</title></Head>
      <BODY bgcolor="silver" >
      <%@ page language="java" import="java.sql.*" %>

	 <%
	  
 	    Class.forName("org.postgresql.Driver");
 	    	    Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/sample", "postgres", "ankur");


            Statement stmt = conn.createStatement();
            ResultSet rs;

      
      
 String StrUser = request.getParameter("username");
 String Age = request.getParameter("age"); 
  
stmt.executeUpdate("INSERT INTO tab1 VALUES ('ankur',21);" );
stmt.close();
     conn.close();

            %>

    </BODY>
      </HTML>

Edited by ankurmawanda: n/a

0

Again, this cannot be the code you are executing. Where in the SQL statements you are using does a "[" appear? As, the error that is appearing is indicating that there is a "[" in the SQL that it tried to execute.

0

sir i have seen thoroghtly in my code
and i am sure this is the page i am acessing on my apache

what could be possible reason for this


thanx a lot for baring with me

0

sir i used tried another page and i am still getting the same error
can some one tell me the possible explaination where am i going wrong

i colleceted the data from user using a html page and trying to post it in a db

the jsp file is[ICODE]<%@ page language="java" import="java.sql.*" %>
      <%
      String url = "jdbc:postgresql://localhost:5432/sample", user="postgres", passwd="ankur";
      Class.forName ("org.postgresql.Driver");
      Connection myConn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/sample", "postgres", "ankur");
      Statement myStatement = myConn.createStatement ();
 String StrUser = request.getParameter("username");
 String StrPass = request.getParameter("password"); 
 String FirstName = request.getParameter("firstname"); 
 String MiddleName = request.getParameter("middlename"); 
 String LastName = request.getParameter("lastname");
String Dob = request.getParameter("dob"); 
 String City = request.getParameter("city"); 
 String State = request.getParameter("state"); 
 String Country = request.getParameter("country"); 
myStatement.executeUpdate("INSERT INTO Details([UserName], [Password], [FirstName], [MiddleName], [LastName],[DOB], [City], [State], [Country]) VALUES ('"+StrUser+"', '"+StrPass+"' , '"+FirstName+"', '"+MiddleName+"' , '"+LastName+"', '"+Dob+"', '"+City+"', '"+State+"', '"+Country+"')"); 
myStatement.close();
      myConn.close();

            %>

Edited by pyTony: fixed formating

Attachments screenshot.JPG 156.78 KB
1

Well now, that's more like it. See those brackets "[" "]"? Those are not legal sql. That is MS stuff.

0

thank you very much for pointing that out....i am now able to post static queries to the database


ie

myStatement.executeUpdate("INSERT INTO tab1 VALUES ('a',12)");

can you please tell me how to write a proper dyanamic query

thnx in advance

Edited by ankurmawanda: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.