Click here to Skip to main content
15,885,278 members

Error When Insert in Database

Khudha Bakhsh Mari asked:

Open original thread
Hi friends i am new to java i am working on jsp so i want to insert in database it is showing this error , so how can i solve it can any one help me please... following error is occuring?
In this file i am getting parameters and initilizing beans
JavaScript
<%@page import="com.dryclean.web.controller.AdduserBeans;"%>
<%@page import="com.dryclean.web.controller;" %>
<%@ 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);
response.sendRedirect("user_page.jsp");
%>


Java
public static void SaveCustomer(AdduserBeans adduser)throws Exception
	{
		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;
		String query="INSERT INTO customers (customer_id, first_name,last_name,contact,address) VALUES('null','"+adduser.getCustomer_fname()+"','"+adduser.getCustomer_lname()+"','"+adduser.getCustomer_cellnumber()+"','"+adduser.getCustomer_address()+"')";
		try{
			Class.forName(driver);
			con = DriverManager.getConnection (dbUrl+db,user,pass);
			stmt = con.createStatement();
			//stmt.executeQuery(query);
			//stmt.executeQuery(sql)
			 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");
		}
	}


and it is showing this error

An error occurred at line: 5 in the jsp file: /addcustomer_do.jsp
AdduserBeans cannot be resolved to a type
2: <%@page import="com.dryclean.web.controller;" %>
3: <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
4: <%
5: AdduserBeans addCust_obj=new AdduserBeans();
6: addCust_obj.setCustomer_fname(request.getParameter("add_customer_fname"));
7: addCust_obj.setCustomer_lname(request.getParameter("add_customer_lname"));
8: addCust_obj.setCustomer_address(request.getParameter("add_customer_cellnumber"));
Tags: Javascript, Java, SQL

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