Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSERT
- <%@ page import ="java.sql.*"%>
- <form method="POST">
- ID Transaksi : <input type = "text" name = "id">*</br>
- Nama Barang : <input type = "text" name = "nm">*</br>
- Harga Satuan : <input type = "text" name = "hrgs">*</br>
- Jumlah : <input type = "text" name = "jml">*</br>
- Jenis Transaksi :
- <select name="jnst" id="jnst">
- <option value=jenis1 selected="selected">Pengeluaran</option>
- <option value=jenis2>Pemasukan</option>*
- </select><br/>
- Tanggal Trans : <input type = "text" name = "tglt">*(YYYY-MM-DD)</br>
- <input type="Submit" name="submit" value="Insert">
- </form>
- <%
- String id = request.getParameter("id");
- String nm = request.getParameter("nm");
- String hrgs = request.getParameter("hrgs");
- String jml = request.getParameter("jml");
- String jnst1 = request.getParameter("jnst");
- String tglt = request.getParameter("tglt");
- String bs=request.getParameter("submit");
- if (bs==null){
- return;}
- //if(id == null || nm == null || hrgs == null || jml == null || hrgs2 = null || jnst1 == null || tglt == null){
- out.println("Isi semua data yang bertanda *");
- //}
- int hrgs2 = Integer.parseInt(hrgs);
- int jml2 = Integer.parseInt(jml);
- int total = hrgs2*jml2;
- String total2 = total+"";
- if(jnst1.equals("jenis1")){
- jnst1= "Pengeluaran";
- }else if(jnst1.equals("jenis2"))
- {
- jnst1= "Pemasukan";
- }
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection koneksi = null;
- koneksi = DriverManager.getConnection("jdbc:mysql://localhost/Transaksi","root","");
- out.println("koneksi berhasil <br />");
- Statement perintah = koneksi.createStatement();
- int hasil = perintah.executeUpdate("insert into view(id_transaksi, nama_barang, harga_satuan, jumlah, harga_transaksi, jenis_transaksi, tgl_transaksi) values('"+id+"', '"+nm+"', '"+hrgs+"', '"+jml+"','"+total2+"','"+jnst1+"','"+tglt+"')");
- out.println(hasil);
- koneksi.close();
- out.println("Koneksi ditutup <br />");
- }
- catch(Exception e)
- {
- out.println(e);
- }
- %>
- <a href= "view.jsp">Lihat Tabel</a>
Add Comment
Please, Sign In to add comment