2 Replies - 537 Views - Last Post: 05 October 2013 - 09:16 AM Rate Topic: -----

#1 vamsi1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 03-October 13

no value specified for parameter?

Posted 05 October 2013 - 04:47 AM

package com.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/DbConnection")
public class DbConnection extends HttpServlet 
{
	private static final long serialVersionUID = 1L;
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		response.setContentType("text/html");
		PrintWriter out=response.getWriter();
		
		String n= request.getParameter("username");
		String p= request.getParameter("password");
		System.out.println("hi "+n+"!");
		try
		{
			   String URL="jdbc:mysql://localhost:3306/data";
			   String PASS="";
			   String ROOT="root";
		   Class.forName("com.mysql.jdbc.Driver");
		   Connection con= DriverManager.getConnection(URL,ROOT,PASS);
		   System.out.println("database connection successfully");
		   PreparedStatement ps= con.prepareStatement("insert into example1(username,password) values(?,?)");
		   ps.setString(1, n);
		   ps.setString(1, p);
		   System.out.println("inserted successfully");
		   
		 
			      int rs = ps.executeUpdate();  
			      ps.close();
		 }
		catch(Exception e)
		{
			System.out.println(e);
		}
		
		out.close();
	}
}




i cant understand what is the problem please solve, im new to java

Is This A Good Question/Topic? 0
  • +

Replies To: no value specified for parameter?

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2685
  • View blog
  • Posts: 11,345
  • Joined: 20-September 08

Re: no value specified for parameter?

Posted 05 October 2013 - 05:17 AM

Quote

            ps.setString(1, n);
            ps.setString(1, p);

You use the same parameter index twice
Was This Post Helpful? 0
  • +
  • -

#3 vamsi1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 03-October 13

Re: no value specified for parameter?

Posted 05 October 2013 - 09:16 AM

thanking you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1