在数据库中插入时出错 [英] Error When Insert in Database

查看:86
本文介绍了在数据库中插入时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 朋友,我是java的新手,我正在jsp上工作,因此我想在数据库中插入它正在显示此错误,因此,我该如何解决呢?有人可以帮助我吗...发生以下错误?
在此文件中,我正在获取参数并初始化bean

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

<%@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");
%>





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

推荐答案

我在问题和某些标签中添加了某种格式. />
似乎不知道AdduserBeans -它已添加到内部版本中吗?检查构建文件,AdduserBeans 可能未标记为要添加到构建中.
I added some format to the question and some tags.

Seems like the AdduserBeans is not known - is it added to the build? Check the build files, the AdduserBeans might not be marked to be added to the build.


这篇关于在数据库中插入时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆