Visualizzazione post con etichetta java. Mostra tutti i post
Visualizzazione post con etichetta java. Mostra tutti i post

sabato 15 marzo 2008

MySQL - SHOW STATUS in Java

Ecco il codice per fare lo SHOW STATUS di MySQL in Java. Per fare questo programma ho impiegato 15 minuti. E' veramente semplice. Seguite i commenti.

// showstatus.java
import java.sql.*;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
class showstatus
{
private static Connection conDb;
// check the correct values of followings variables
private static String JDBC_DRIVER = "com.mysql.jdbc.Driver";
private static String JDBC_URL = "jdbc:mysql://127.0.0.1:3306/";
private static String JDBC_NAME = "root";
private static String JDBC_PASSWORD = "password";
public static void main(String[] args)
{
System.out.println( "Start" );
// driver
try
{
Class.forName( JDBC_DRIVER );
}
catch (Exception ex)
{
System.out.println( "Error Class.forName "+ex );
ex.printStackTrace();
System.exit(0);
}
// connection
try
{
conDb = DriverManager.getConnection(JDBC_URL, JDBC_NAME, JDBC_PASSWORD);
}
catch (Exception ex)
{
System.out.println( "Error getConnection "+ex );
ex.printStackTrace();
System.exit(0);
}
// Show Status
String query = "SHOW STATUS";
PreparedStatement ps;
ResultSet rs;
try
{
ps = conDb.prepareStatement(query);
try
{
rs = ps.executeQuery( query );
int cnt = 0;
try
{
while (rs.next()) // are there more 'Variable_name'?
{
String variableName = rs.getString("Variable_name");
String value = rs.getString("Value");
System.out.println( "variableName: "+variableName+" - Value: "+value );
// NOTE: value is String ...
// Is possible to convert it with the fllowing istruction:
// Integer.parseInt( value )); // only if numeric!!!
//System.out.println( "Integer.parseInt( value ) "+Integer.parseInt( value ));
}
}
catch (Exception ex)
{
System.out.println( "Error executeQuery "+ex );
ex.printStackTrace();
System.exit(0);
}
}
catch (Exception ex)
{
System.out.println( "Error executeQuery "+ex );
ex.printStackTrace();
System.exit(0);
}
}
catch (Exception ex)
{
System.out.println( "Error prepareStatement "+ex );
ex.printStackTrace();
System.exit(0);
}
System.out.println( "End" );
}
}

giovedì 15 novembre 2007

Le release di Java

Ecco le versioni di Java (aggiornate al 14/11/2007):

Java 1.0 (Oak) 1995
Java 1.1
JDK 1.1.4 (Sparkler) September 12, 1997
JDK 1.1.5 (Pumpkin) December 3, 1997
JDK 1.1.6 (Abigail) April 24, 1998
JDK 1.1.7 (Brutus) September 28, 1998
JDK 1.1.8 (Chelsea) April 8, 1999
J2SE 1.2 (Playground) December 4, 1998
J2SE 1.2.1 (none) March 30, 1999
J2SE 1.2.2 (Cricket) July 8, 1999
J2SE 1.3 (Kestrel) May 8, 2000
J2SE 1.3.1 (Ladybird) May 17, 2001
J2SE 1.4.0 (Merlin) February 13, 2002
J2SE 1.4.1 (Hopper) September 16, 2002
J2SE 1.4.2 (Mantis) June 26, 2003
J2SE 5.0 (1.5.0) (Tiger) September 29, 2004
Java SE 6 (1.6.0) (Mustang) December 11, 2006 [3]
Java SE 7 (1.7.0) (Dolphin) anticipated for January 2009

Attualmente uso JDK7 1.7.0-ea-b23 (ovvero la build 23). Si può scaricare
dal sito https://jdk7.dev.java.net/ (dopo essersi registrati).
Per vedere che versione di Java avete date il seguente comando dal prompt dei comandi:
  • java -version

lunedì 14 maggio 2007

JDBC: da DB2 a MySQL

Da un mesetto ho iniziato a utilizzare JDBC in Java. Ho iniziato con MySql che è completamente gratis e poi ho scaricato DB2 Express-C dell'IBM. Dopo un mesetto ho deciso di usare MySql. A dire la verità usare l'uno o l'altro non mi comportava nessun problema, tanto per quello che mi serve vanno bene tutti e due. Ma la documentazione che ho trovato su MySql è formidabile rispetto al DB2, specialmente ciò la documentazione trovata sul P2P. Pubblicherò a breve qualche programmino in Java che utilizza JDBC su MySql.

domenica 15 aprile 2007

luxjava

Ho intenzione di appoggiare il mio nuovo sito dedicato allo studio di java:

Il sito e il blog servono a me e a tutti quelli che iniziano a studiare il linguaggio java. Si, l'obiettivo è "studiare insieme" java! Questo Blog è solo un appoggio al sito: raccoglie commenti e suggerimenti utili a me e tutti Voi.
Ma perchè faccio un Blog di appoggio ad un sito web sul linguaggio java? Come ho intenzione di organizzarmi? Ecco una sintesi di quanto ho intenzione di fare:
  • aggiungo un argomento al sito web
  • metto nel sito web le spiegazioni sull'argomento
  • metto nel sito web l'eventuale sorgente da scaricare
  • aggiungo immagini sul sito web
  • metto nel sito il link al blog relativo all'argomento
  • aggiungo un post nel blog sull'argomento
  • aggiungo eventuali immagini
  • faccio il ri-post di commenti di maggior interesse nel sito web
Grazie in anticipo a tutti Voi e ... ricordateVi: lasciate un commento!