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

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.

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>

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.

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

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();

            %>

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

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

See the jdbc tutorials paying attention to the preparedstatement portion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.