Click here to Skip to main content
15,894,740 members

Problem in Inserting in Database Using Jsp

Khudha Bakhsh Mari asked:

Open original thread
hi
i am trying to insert in database in this way using jsp but it is not working can any one help me where i have make an mistake....




JavaScript
<%@page import="com.dryclean.web.controller.DBUtil"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%
/*AdduserBeans addCust_obj=new AdduserBeans();
addCust_obj.setCustomer_fname(request.getParameter("add_customer_fname"));
addCust_obj.setCustomer_lname(request.getParameter("add_customer_lname"));
addCust_obj.setCustomer_address(request.getParameter("add_customer_cellnumber"));
addCust_obj.setCustomer_cellnumber(request.getParameter("add_customer_address"));
*/
//DBUtil.SaveCustomer(addCust_obj);
//System.out.println(adduser.getCustomer_fname());
/*String dbUrl = "jdbc:mysql://localhost:3306/";
String db = "dry_cleaner";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "";*/
Connection con =null;
Statement stmt = null;
int updateQuery=0;
String query="INSERT INTO customers (customer_id, first_name,last_name,contact,address) VALUES('null','"+request.getParameter("add_customer_fname")+"','"+request.getParameter("add_customer_lname")+"','"+request.getParameter("add_customer_cellnumber")+"','"+request.getParameter("add_customer_address")+"')";
try{
	con = DBUtil.getConnection("jdbc:mysql://localhost:3306/","dry_cleaner","com.mysql.jdbc.Driver","root","");
	//Class.forName(driver);
	//con = DriverManager.getConnection (dbUrl+db,user,pass);
	System.out.println("connection success fully");
}catch(Exception ex){
	System.out.println("Connection error");
	}
try{
	updateQuery=stmt.executeUpdate(query);
	  if (updateQuery != 0) {
		  System.out.println("table is created successfully and " + updateQuery + " row is inserted.");
	  }
	//stmt = con.createStatement();
	//stmt.executeUpdate(query);
	/*
	 QueryString = "INSERT INTO user_master1(User_Name,UserId,User_Pwd)
 VALUES ('Mahendra',"+ "'mahendra25','1213456')";
  updateQuery = statement.executeUpdate(QueryString);
  if (updateQuery != 0) {
  System.out.println("table is created successfully and " + updateQuery
 + " row is inserted.");
	*/
	 /*if(stmt.executeUpdate(query)>0){
		   System.out.print("Records inserted");
		  }else{
		   System.out.print("insertion faild");
		  }*/
}catch(Exception ex){
	System.out.println("Query :"+query);
	//throw new Exception("Query Error");
}
response.sendRedirect("user_page.jsp");
%>
Tags: Java, JSP

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900