aglet + database mySql - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

aglet + database mySql

scy_sasukescy_sasuke Posts: 4Member
hi all, iam developing mobile agent using aglet 2.0.2 and
mysql-connector-java-5.1.14 to connect database mysql.
i was create simple code to display some data from database.
then i compile it and its work, but when i running with tahiti server there
is error and no data display.
anyone know the problem??
NB : i try create with simple java program with this code is works fine.

regards,
scifo

[b]this is error message in console:[/b]

database failure: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The
driv er has not received any packets from the server.


here is the code :

package examples.database;

import com.ibm.aglet.*;
import java.io.*;
import java.util.*;
import java.net.*;
import java.sql.*;

public class aglet_database extends Aglet {

private transient Timer timer = null;

public void onCreation(Object init) {
log("Active"); setText("Master pencarian aktif");
AgletID id = getAgletID();

}

public void run() {
System.out.println("Tampil no pencarian");
Connection conn = null;
Statement st = null;
ResultSet rs = null;

try
{
Class.forName("com.mysql.jdbc.Driver"); // koneksi driver database

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cobadb","root","scifoanggi"); // koneksi ke mySQL
//st = this.conn.createStatement();
//rset = st.executeQuery(sqlQuery); // ekseskusi quey SQL

// Statement SQL statik
st = conn.createStatement();

// Eksekusi SQL-statement untuk tabel "buku"
rs = st.executeQuery("SELECT * FROM customer");

// Ambil data result-set
ResultSetMetaData rsmd = rs.getMetaData();
int nColumn = rsmd.getColumnCount();

// Tampilkan judul kolom
for (int i = 1; i <= nColumn; i++) {
System.out.print(rsmd.getColumnName(i) + " | ");
}
System.out.println("
");

// Tampilkan hasil query berupa data result-set dari tabel
while (rs.next()) {
System.out.println(rs.getString(1) + " " +
rs.getString(2) + " " +
rs.getInt(3) + " " +
rs.getString(4) + " " +
rs.getInt(5));
}

}

catch (ClassNotFoundException e) {
System.err.println("driver failure: " + e.getMessage());
}
catch (SQLException e)
{
System.err.println("database failure: "+ e.getMessage());
}

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

try
{ if (st != null ) st.close(); }
catch (SQLException sqle) {}

try
{ if (conn != null ) conn.close(); }
catch (SQLException sqle) {}

}

}

public void onDisposing() {
log("Disposing...");
if (timer != null) {
timer.cancel();
}
log("Bye bye agent search master!");
}

private void log(String message) {
System.out.println("Status Agent Search Anak : " + message);
}
}
Sign In or Register to comment.