Tugas Jeni 3 Saudara Bayu

December 27, 2008 at 4:52 am 1 comment


Mensikapi apa yang ditanyakan saudara Bayu tentang Tugas Jeni 3 yang sampai sekarang belum jadi juga, sayapun telah menerima hasil karya saudara Bayu yang hampir selesai, sehingga sayapun coba ikut turun tangan dan sedikit memodif tampilan yang setidaknya bisa menampilkan transaksi per no nota. Saya postingkan disini coding file NotaPembelian.java sebagai berikut :

package com.nawolo.simpledatabase;
import java.sql.*;
public class NotaPembelian {
private String nonota = null;
private String username = “root”;
private String password = “”;
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;
private DatabaseMetaData dmd;
private ResultSetMetaData rsmd;
public NotaPembelian() {
}
public String getNonota() {
return nonota;
}
public void setNonota(String nonota) {
this.nonota = nonota;
}
public String aksesNotaBeli() {
String dbHTML = “”;
if (nonota == null) {
password = “”;
return dbHTML;
}
if (nonota.equals(“”)) {
password = “”;
dbHTML = “Koneksi Error. Nama Tabel Kosong”;
return dbHTML;
}
dbHTML += “<p>Nomor Transaksi = ” + nonota + “<br>”;
try {
Class.forName(“org.gjt.mm.mysql.Driver”);
con = DriverManager.getConnection(
“jdbc:mysql://localhost:3306/penjualan”, “root”, “123”);
stmt = con.createStatement();
rs = stmt.executeQuery(“SELECT * FROM qpembelian WHERE nonota =”+”‘”+nonota+”‘”);
rs.first();
dbHTML += “Tanggal Transaksi = ” + rs.getString(2) + “<br>”;
dbHTML += “Tanggal Transaksi = ” + rs.getString(3) + “<br></p>”;
int nColom = rsmd.getColumnCount();
dbHTML += “<table border=\”1\” cellpadding=\”4\”><tr>”;
dbHTML +=”<th>No</th>”;
for (int i = 4; i <= nColom; i++) {
dbHTML += “<th>” + rsmd.getColumnName(i) + “</th>”;
}
dbHTML += “</tr>”;

int nomor = 1;
int totalbiaya = 0;
rs.beforeFirst();

while (rs.next()) {

dbHTML += “<tr>”;
dbHTML +=”<td>”+nomor+”</td>”;
for (int i = 4; i <= nColom; i++) {
dbHTML += “<td>” + rs.getString(i) + “</td>”;
if (i==9){
totalbiaya = totalbiaya + Integer.parseInt(rs.getString(i));
}
}
nomor++;
dbHTML += “</tr>”;
}
dbHTML +=”<tr><td colspan = 6>Total Biaya</td><td align = right> “+ totalbiaya+”</td></tr></table>”;

} catch (ClassNotFoundException e) {
dbHTML += “<p>Tidak dapat mengakses Driver” +
e.getMessage() + “</p>”;
} catch (SQLException e) {
dbHTML += “<p>SQL Error, AppServ harap diStart dulu ” +
e.getMessage() + “</p>”;
} finally {

try {
if (rs != null) rs.close();
} catch (SQLException sqle) {}
try {
if (stmt != null) stmt.close();
} catch (SQLException sqle) {}
try {
if (con != null) con.close();
} catch (SQLException sqle) {}
}

password = “”;
return dbHTML;
}

public void setUsername(String username) {
this.username = username;
}

public void setPassword(String password) {
this.password = password;
}
}

Sehingga hasil runningnya sebagai berikut :

bayuweb

Entry filed under: Web Programming. Tags: .

Membuat table t di SPSS Beasiswa S2 Master Program of Computational Logic German

1 Comment Add your own

  • 1. jingklak  |  December 27, 2008 at 6:21 am

    Ralat, pada tampilan di atas Tanggal Transaksinya ada dua, mestinya yang atas Tanggal Transaksi, yang bawah Suplier

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


December 2008
M T W T F S S
« Nov   Jan »
1234567
891011121314
15161718192021
22232425262728
293031  

%d bloggers like this: