|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Mar 2004
Messaggi: 1451
|
Applet + tomcat + mysqlconnector
Dovrei utilizzare una applet per accedere ad un base di dati in mysql, ho messo su i driver mysql-connector ma quando provo a connettermi ricevo
Error accessing DB Error code is : 0 Error message is :No suitable driver Codice:
/*
* This sample shows how to list all the names from the Persone table
*/
// You need to import the java.sql package to use JDBC
import java.sql.*;
import java.awt.*;
import java.applet.*;
import javax.swing.*;
public class test extends JApplet {
TextArea ta = new TextArea("In attesa di connessione...",30,70);
public void init()
{
setLayout(new BorderLayout());
add("Center",ta);
try {
// Load the Mysql JDBC driver
try {
Class.forName ( "com.mysql.jdbc.Driver").newInstance();
} catch (ClassNotFoundException e) {
System.out.println ("Mysql device driver does not exist");
System.exit(1);
}
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:mysql:localhost:3306/DB?user=username&password=");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery (" select ID, Cognome, Nome, Tel , Email,Homepage from Persone");
StringBuffer buf = new StringBuffer();
// Iterate through the result and print the employee names
while (rset.next ()) {
buf.append (rset.getString (1)+" "+rset.getString(2)+" "+
rset.getString(3)+" "+rset.getString(4)+" "+rset.getString(5)+"\n");
}
ta.setText(buf.toString());
// Close the RseultSet
rset.close();
// Close the Statement
stmt.close();
// Close the connection
conn.close();
} catch (SQLException e) {
System.out.println("Error accessing DB ");
System.out.println(" Error code is : "+e.getErrorCode());
System.out.println(" Error message is :"+e.getMessage());
}
}
}
P.s Kingv se hai tempo e msn, vorrei parlarti due minuti
__________________
Ciao ~ZeRO sTrEsS~ Ultima modifica di beppegrillo : 21-01-2005 alle 15:31. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Jan 2001
Città: Milano
Messaggi: 5707
|
il problema e' che il browser (o l'appletviewer) non conosce le classi del driver jdbc di mysql.
devi usare gli attributi codebase e archive del tag applet. mettiamo che pippo.jar e' il jar dell'applet e mysql.jar quello dei driver jdbc. sul tuo web server li metti nella stessa directory , ad esempio: http://tuoweb.com/applet/ a questo punto setti l'attributo codebase a "http://tuoweb.com/applet/" e archive a "pippo.jar,mysql.jar". Così facendo entrambi gli archivi vengono scaricati e messi in classpath dal runtime java del browser. ho "acceso" msn |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jan 2001
Città: Milano
Messaggi: 5707
|
contrordine, MSN non funziona , quei simpaticoni del networking me ml'hanno tappato
![]() mi trovi stasera sul tardi a casa, altrimenti per mail |
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Mar 2004
Messaggi: 1451
|
Quote:
Credevo bastasse mettere le classi nella dir ext di jre, invece con le applet và specificato. P.s Per msn, prova a vedere se ti funziona questo simpatico programmino
__________________
Ciao ~ZeRO sTrEsS~ |
|
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Jan 2001
Città: Milano
Messaggi: 5707
|
Quote:
ho linux. cmq ho risolto minacciando di morte un paio di sistemisti. [email protected] |
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Mar 2004
Messaggi: 1451
|
Come aggiungo delle chiavi nascoste ad un componente JcomboBox??
__________________
Ciao ~ZeRO sTrEsS~ |
|
|
|
|
|
#7 | |
|
Senior Member
Iscritto dal: Jan 2001
Città: Milano
Messaggi: 5707
|
Quote:
nascoste? intendi dei valori che non vengono visualizzati? perche' vuoi farlo? |
|
|
|
|
|
|
#8 | |
|
Senior Member
Iscritto dal: Mar 2004
Messaggi: 1451
|
Quote:
In html è possibile inserire due valori, uno quello che viene visualizzato nella combobox e l'altro che risulta essere la chiave, credevo fosse possibile anche con i JComboBox.
__________________
Ciao ~ZeRO sTrEsS~ |
|
|
|
|
|
|
#9 | |
|
Senior Member
Iscritto dal: Jan 2001
Città: Milano
Messaggi: 5707
|
Quote:
no, l'approccio più semplice e' quello di conservare in memoria una struttura dati (una Map ad esempio) che ti permetta di associare al valore della combo gli altri. Probabilmente è possibile utilizzare un approccio piu' sofisticato scrivendosi un ComboBoxModel custom, ma non e' detto che ne valga la pena. |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 10:02.




















