Java

Moderators: zibadian
Number of threads: 7832
Number of posts: 18231

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
aglet + database mySql Posted by scy_sasuke on 3 May 2011 at 3:39 AM
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

this is error message in console:

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("\n");

// Tampilkan hasil query berupa data result-set dari tabel
while (rs.next()) {
System.out.println(rs.getString(1) + "\t" +
rs.getString(2) + "\t" +
rs.getInt(3) + "\t" +
rs.getString(4) + "\t" +
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);
}
}



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.