mariadb error BIGINT UNSIGNED value is out of range in

waw ada error pada mariadb “BIGINT UNSIGNED value is out of range in” bla bla bla

Bismillah

q> Cek query yang panjangnya minta ampun terus jalankan errornya :
“Data Truncation error occured on a write  of column 0Data was 0 bytes long and 0 bytes were transferred.”

q> Sedangkan log pada aplikasi terdapat pesan error seperti ini :
“BIGINT UNSIGNED value is out of range in ‘(`dtl`.`TOTAL_AMOUNT` – ((`dtl`.`QTY` – `d`.`QTY`) * `dtl`.`TOTAL_AMOUNT`))'”

q> Cek tipe data untuk kolom total_amount  dengan perintah

show create table dtl_jual_part;

ternyata tipe datanya int unsigned,

q> cari referesensi pada stackoverflow mengenai error ini, dapat sumber ini [1]

q> Coba untuk alter table untuk kolom tersebut, menjadi signed

alter table dtl_jual_part modify TOTAL_AMOUNT int(11) DEFAULT NULL;

q> Jalankan lagi aplikasi, waw errornya hilang

sumber [1] : http://stackoverflow.com/questions/5605085/bigint-unsigned-value-is-out-of-range

Alhamdulillah

 

mysql mengurutkan angka yang tipenya varchar

bagaimana caranya ya mengurutkan data yang isinya angka tetapi tipe datanya adalah varchar pada mysql

Bismillah

q> Misalnya kita punya tabel seperti ini

create table coba (number varchar(3) primary key, nilai varchar(20) );

q> Isi tabel dengan perintah ini :

INSERT INTO coba (number,nilai) VALUES ('1','satu');
INSERT INTO coba (number,nilai) VALUES ('2','dua');
INSERT INTO coba (number,nilai) VALUES ('3','tiga');
INSERT INTO coba (number,nilai) VALUES ('10','sepuluh');
INSERT INTO coba (number,nilai) VALUES ('12','dua belas');

q> tampilkan data dengan query ini :

select * from coba order by number;

Selection_796

q> tampilkan lagi dengan query ini :

select * from coba order by number+0;

Selection_797

Alhamdulillah

 

 



 

server side validator menggunakan hibernate validator

Server side validator, melanjutkan tulisan sebelumnya, aplikasi menggunakan framework spring mvc, spring data jpa dan hibernate entity manager

Bismillah

q> Melanjutkan tulisan ini :
https://saifiahmada.wordpress.com/2014/12/25/membuat-crud-sederhana-spring-mvc/

q> Langkah-langkah praktek :

1. tambahkan mvc namespace pada dispatcher-servlet
2. tambahkan tag <mvc:annotaion-driven /> pada dispatcher-servlet
3. tambahkan dependency hibernate validator 5.1.0 final pada pom.xml
4. tambahkan annotation pada domain object
5. tambahkan @Valid dan BindingResult pada parameter method add pada controller
6. tambahkan tag <form:errors> pada JSP
7. testing hasil

q> – – – mulai – – –

1. tambahkan mvc namespace pada dispatcher-servlet

Selection_637

2. tambahkan tag <mvc:annotaion-driven /> pada dispatcher-servlet

<mvc:annotaion-driven />

3. tambahkan dependency hibernate validator 5.1.0 final pada pom.xml

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.0.Final</version>
</dependency>

4. tambahkan annotation pada domain object

@Id
 @GeneratedValue
 private Integer id;
 
 @Size(min=3, message="minimal 3 karakter!")
 @NotBlank
 private String nama;
 
 @Size(min=5, message="minimal 5 karakter!")
 @NotBlank
 private String alamat;
 @Size(min=11, message="minimal 11 karakter!")
 @NotBlank
 private String noHp;

5. tambahkan @Valid dan BindingResult pada parameter method add pada controller

@RequestMapping(value = "/add", method=RequestMethod.POST)
public String add(Model model, @Valid @ModelAttribute("customer") Customer customer, BindingResult result){

logger.info("method add");

if (result.hasErrors()) {
model.addAttribute("customers", customerService.findAll());
return "customer";
}
customerService.save(customer);
return "redirect:/customer/awal.html?success=true";
}

6. tambahkan tag <form:errors> pada JSP

<form:errors path="nama" />
<form:errors path="alamat" />
<form:errors path="noHp" />

7. testing hasil

Selection_636

Ketika tombol simpan ditekan, maka akan muncul pesan bahwa minimal karakter harus dipenuhi

Alhamdulillah

membuat crud sederhana spring mvc

Create Read Update Delete menggunakan spring mvc, spring data jpa, hibernate entity manager, tiles, mysql

Bismillah

q> Melanjutkan tulisan sebelumnya :
https://saifiahmada.wordpress.com/2014/12/13/menambah-menu-stok/

q> Langkah-langkah praktek :
1. Buat bean entity Customer
2. Buat interface CustomerRepositroy
3. Buat class CustomerService
4. Tambahkan definition pada general.xml
5. Tambahkan menu pada classic.jsp
6. Buat file customer.jsp pada /WEB-INF/jsp/
7. Tambahkan class controller CustomerController

1. Buat bean entity Customer

package com.saifiahmada.maven.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Customer {

	@Id
	@GeneratedValue
	private Integer id;

	private String nama;

	private String alamat;

	private String noHp;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNama() {
		return nama;
	}

	public void setNama(String nama) {
		this.nama = nama;
	}

	public String getAlamat() {
		return alamat;
	}

	public void setAlamat(String alamat) {
		this.alamat = alamat;
	}

	public String getNoHp() {
		return noHp;
	}

	public void setNoHp(String noHp) {
		this.noHp = noHp;
	}

}

2. Buat interface CustomerRepositroy

package com.saifiahmada.maven.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.saifiahmada.maven.entity.Customer;

public interface CustomerRepository extends JpaRepository<Customer, Integer> {

}

3. Buat class CustomerService

package com.saifiahmada.maven.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.saifiahmada.maven.entity.Customer;
import com.saifiahmada.maven.repository.CustomerRepository;

@Service
public class CustomerService {

	@Autowired
	private CustomerRepository customerRepository;

	public void save(Customer customer) {
		customerRepository.save(customer);
	}

	public List<Customer> findAll() {
		return customerRepository.findAll();
	}

}

4. Tambahkan definition pada general.xml

	<definition name="customer" extends="common">
		<put-attribute name="title" value="Customer" />
		<put-attribute name="body" value="/WEB-INF/jsp/customer.jsp" />
		<put-attribute name="current" value="customer" />
	</definition>

5. Tambahkan menu pada classic.jsp

<li class="${current == 'customers' ? 'active' : '' }">
<a href="/customer/awal.html">Customer</a></li>

6. Buat file customer.jsp pada /WEB-INF/jsp/

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ include file="../layout/taglib.jsp"%>

<form:form commandName="customer" action="/customer/add.html"
	cssClass="form-horizontal">

	<c:if test="${ ! empty customer.nama }">
		<div class="form-group">
			<label for="id" class="col-sm-2 control-label">Id</label>
			<div class="col-sm-10">
				<form:input path="id" cssClass="form-control" readonly="true" disabled="true" />
				<form:hidden path="id"/>
			</div>
		</div>

	</c:if>

	<div class="form-group">
		<label for="nama" class="col-sm-2 control-label">Nama</label>
		<div class="col-sm-10">
			<form:input path="nama" cssClass="form-control" />
		</div>
	</div>

	<div class="form-group">
		<label for="alamat" class="col-sm-2 control-label">Alamat</label>
		<div class="col-sm-10">
			<form:input path="alamat" cssClass="form-control" />
		</div>
	</div>

	<div class="form-group">
		<label for="noHp" class="col-sm-2 control-label">No HP</label>
		<div class="col-sm-10">
			<form:input path="noHp" cssClass="form-control" />
		</div>
	</div>

	<input type="submit" value="Simpan" class="btn btn-success" />
	<a href="/customer/awal.html" class="btn btn-success">Reset</a>

</form:form>

<br />

<table class="table table-bordered table-hover table-striped">
	<thead>
		<tr>
			<th>Nama</th>
			<th>Alamat</th>
			<th>No. HP</th>
			<th>Edit</th>
			<th>Delete</th>
		</tr>
	</thead>
	<tbody>
		<c:forEach items="${customers}" var="c">
			<tr>
				<td>${c.nama }</td>
				<td>${c.alamat }</td>
				<td>${c.noHp }</td>
				<td><a href="/customer/edit/${c.id}.html">Edit</a></td>
				<td><a href="/customer/delete/${c.id}.html">Delete</a></td>
			</tr>
		</c:forEach>
	</tbody>
</table>

7. Tambahkan class controller CustomerController

package com.saifiahmada.maven.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.saifiahmada.maven.entity.Customer;
import com.saifiahmada.maven.service.CustomerService;

@Controller
@RequestMapping(value = "/customer")
public class CustomerController {

	@Autowired
	private CustomerService customerService;

	@ModelAttribute("customer")
	public Customer getCustomer(){
		return new Customer();
	}

	@RequestMapping(value="/awal")
	public String awal(Model model){
		model.addAttribute("customer", new Customer());
		model.addAttribute("customers", customerService.findAll());
		return "customer";
	}

	@RequestMapping(value = "/add", method=RequestMethod.POST)
	public String add(@ModelAttribute("customer") Customer customer){
		customerService.save(customer);
		return "redirect:/customer/awal.html";
	}

	@RequestMapping(value = "/edit/{id}")
	public String edit(@PathVariable("id") Integer id, Model model){
		Customer customer = customerService.findOne(id);
		model.addAttribute("customer", customer);
		model.addAttribute("customers", customerService.findAll());
		return "customer";
	}

	@RequestMapping(value = "/delete/{id}")
	public String delete(@PathVariable("id") Integer id, Model model){
		customerService.delete(id);
		model.addAttribute("customers", customerService.findAll());
		return "customer";
	}

}

q> Jalankan jetty untuk melihat hasilnya

q> Awal menu Customer di-klik
Selection_632

q> Edit salah satu data, kemudian tekan tombol simpan

Selection_633

q> Masukkan data baru

Selection_634

q> Data tersimpan

Selection_635

Alhamdulillah