@lob menghasilkan longtext mysql

Ternyata @lob menghasilkan longtext pada mysql

Bismillah

Test coding ini 🙂

private static final long serialVersionUID = 1L;
@Id @GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Column(length=64)
private String id;

@Lob
private String teks;

private String pilihanA;

private String pilihanB;

private String pilihanC;

private String pilihanD;

private String pilihanE;
@Column(length=1)
private String jawaban;
@Column(length=25)
private String tipe;

q> Ketika di-build ( / + running code)Menghasilkan table seperti ini :

testcode

Alhamdulillah

Advertisements

java angka terbilang

 

Bismillah

q> Langsung to coding


/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package testingcode;

/**
*
* @author saifi
*/
public class Terbilang {

private static String bilangLong(Long angka) {
String[] ucapan = {"", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas"};

if (angka.longValue() < 12L) {
System.out.println("masuk < 12L");
return " " + ucapan[angka.intValue()];
}
if (angka.longValue() < 20L) {
System.out.println("masuk < 20L");
return bilangLong(Long.valueOf(angka.longValue() - 10L)) + " Belas";
}
if (angka.longValue() < 100L) {
System.out.println("masuk < 100L");
return bilangLong(Long.valueOf(angka.longValue() / 10L)) + " Puluh" + bilangLong(Long.valueOf(angka.longValue() % 10L));
}
if (angka.longValue() < 200L) {
System.out.println("masuk < 200L");
return " Seratus" + bilangLong(Long.valueOf(angka.longValue() - 100L));
}
if (angka.longValue() < 1000L) {
System.out.println("masuk < 1000L");
return bilangLong(Long.valueOf(angka.longValue() / 100L)) + " Ratus" + bilangLong(Long.valueOf(angka.longValue() % 100L));
}
if (angka.longValue() < 2000L) {
System.out.println("masuk < 2000L");
return " Seribu" + bilangLong(Long.valueOf(angka.longValue() - 1000L));
}
if (angka.longValue() < 1000000L) {
System.out.println("masuk < 1000000L");
return bilangLong(Long.valueOf(angka.longValue() / 1000L)) + " Ribu" + bilangLong(Long.valueOf(angka.longValue() % 1000L));
}
if (angka.longValue() < 1000000000L) {
System.out.println("masuk < 1000000000L");
return bilangLong(Long.valueOf(angka.longValue() / 1000000L)) + " Juta" + bilangLong(Long.valueOf(angka.longValue() % 1000000L));
}
if (angka.longValue() < 1000000000000L) {
System.out.println("masuk < 1000000000000L");
return bilangLong(Long.valueOf(angka.longValue() / 1000000000L)) + " Milyar" + bilangLong(Long.valueOf(angka.longValue() % 1000000000L));
}
if (angka.longValue() < 1000000000000000L) {
System.out.println("masuk < 1000000000000000L");
return bilangLong(Long.valueOf(angka.longValue() / 1000000000000L)) + " Trilyun" + bilangLong(Long.valueOf(angka.longValue() % 1000000000000L));
}

return "";
}

public static void main(String[] args) {
Long angka = 4578000L;
System.out.println("Angka = " + angka);
String terbilang = bilangLong(angka);
System.out.println("Terbilang = " + terbilang);
}

}

q> Hasil :
Selection_833

Alhamdulillah

copy aplikasi web menjadi html full css js image

Saya bikin aplikasi menggunakan spring boot dan jika dijadikan jar ukurannya file jar sekitar 36 MB, tetapi ketika client mau lihat aplikasi yang sudah saya buat, kebetulan client berada pada daerah yang minim koneksi internet, cari solusi dulu

Bismillah

q> gogling ketemu sumber ini [1]

q> aplikasi spring boot ini diakses menggunakan alamat localhost:8787

q> langsung saja, perintahnya menggunakan perintah ini :

wget --limit-rate=200k --no-clobber --convert-links --random-wait -r -p -E -e robots=off -U mozilla http://localhost:8787

Selection_754

q> Hasil tampilan folder :

Selection_755

q> Klo di-zip menghasilkan 389 Kb, tinggal kirim ke client dan tinggal buka index.html

q> Selesai 🙂
Alhamdulillah

sumber:
[1] http://www.kossboss.com/linux—wget-full-website

linux mint java version beda dengan java home

[linux mint] lha kq beda antara java -version dengan echo $JAVA_HOME

Bismillah

q> Awalnya, saya menggunakan jdk 1.7 pada linux mint, kemudian intsall open-jdk 6 (java 1.6), kemudian cek versi dan java_home

Selection_737

q> Dari gambar di atas, menunjukkan java yang berbeda antara perintah java_home dan java -version

q> Jalan kan perintah java alternatives

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java-6-openjdk-i386/bin/java" 1

 

sudo update-alternatives --set java /usr/lib/jvm/java-6-openjdk-i386/bin/java

q> Hasilnya :

Selection_738

q> Selesai, kenapa saya turunkan versinya menjadi open-jdk 6 ? ada yang mau saya compile menggunakan jdk 6 dan targetnya akan dijalankan pada jdk 6.

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

menambah menu stok

Menu stok akan coba kita tambahkan guys 😀

Bismillah

Melanjutkan tulisan sebelumnya :
https://saifiahmada.wordpress.com/2014/12/13/membuat-modal-bootstrap-untuk-form-simpan/

1. buat bean entity Stok

2. buat interface StokRepository

3. buat class StokService

4. buat class StokController

5. buat file stoklist.jsp pada /WEB-INF/jsp/stoklist.jsp

6. tambahkan definition untuk stok pada general.xml

7. tambahkan menu stok pada classic.jsp

8. Insert data stok secara manual

9. testing hasil

q> – – – mulai – – –

1. buat bean entity Stok


package com.saifiahmada.maven.entity;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;

@Entity
public class Stok {

@Id
private Integer id;

private Integer jumlah;

@OneToOne
@JoinColumn(name="id", referencedColumnName="id")
private Barang barang;

public Integer getId() {
return id;
}

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

public Integer getJumlah() {
return jumlah;
}

public void setJumlah(Integer jumlah) {
this.jumlah = jumlah;
}

public Barang getBarang() {
return barang;
}

public void setBarang(Barang barang) {
this.barang = barang;
}

}

2. buat interface StokRepository


package com.saifiahmada.maven.repository;

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

import com.saifiahmada.maven.entity.Stok;

public interface StokRepository extends JpaRepository<Stok, Integer> {

}

3. buat class StokService


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.Stok;
import com.saifiahmada.maven.repository.StokRepository;

@Service
public class StokService {

@Autowired
private StokRepository stokRepository;

public void save(Stok stok){
stokRepository.save(stok);
}

public List<Stok> findAll(){
return stokRepository.findAll();
}

}

4. buat class StokController


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.RequestMapping;

import com.saifiahmada.maven.service.StokService;

@Controller
public class StokController {

@Autowired
private StokService stokService;

@RequestMapping("/stok/list")
public String list(Model model){
model.addAttribute("stoks", stokService.findAll());
return "stok";
}

}

5. buat file stoklist.jsp pada /WEB-INF/jsp/stoklist.jsp


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

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

<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<td>Kode</td>
<td>Barang</td>
<td>Stok</td>
</tr>
</thead>
<tbody>
<c:forEach items="${stoks}" var="stok">
<tr>
<td>${stok.barang.kode}</td>
<td>${stok.barang.nama}</td>
<td>${stok.jumlah}</td>
</tr>
</c:forEach>
</tbody>

</table>

6. tambahkan definition untuk stok pada general.xml

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

7. tambahkan menu stok pada classic.jsp

<li class="${current == 'stok' ? 'active' : '' }"><a
href="/stok/list.html">Stok</a></li>

8. Insert data stok secara manual

Selection_627

9. testing hasil

Selection_628

Alhamdulillah

 

contoh addAttribute spring mvc

Belajar spring mvc : menggunakan addAttribute

Bismillah

q> Melanjutkan project sebelumnya :
https://saifiahmada.wordpress.com/2014/12/08/error-jsp-superclass-javax-servlet-http-httpservlet-pada-eclipse/

q> File jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testing Pang</title>
</head>
<body>

<h1>Selamat datang mas ${welcome}</h1>

</body>
</html>

q> File IndexController.java


package com.saifiahmada.maven.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class IndexController {

@RequestMapping("/index")
public String index(){
return "/WEB-INF/jsp/index.jsp";
}

@RequestMapping("/testing")
public String testing(ModelMap model) {
String nama = "Saifi Ahmada";
model.addAttribute("welcome", nama);
return "/WEB-INF/jsp/testing.jsp";
}
}

q> Hasilnya
Selection_589

Alhamdulillah