Salve a tutti,
stavo cercando di collegarmi al mio database mediante questo codice:
Se però l'eseguo mi da il seguente errore:codice:import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; // Notice, do not import com.mysql.jdbc.* // or you will have problems! // add as jar to the project public class LoadDriver { public static void main(String[] args) { try { // The newInstance() call is a work around for some // broken Java implementations // Dal sito di MySQL //N.B. Líuso del newInstance() ha lo scopo di //verificare la correttezza del driver (ossia la //capacita di istanziare oggetti // líoggetto creato Ë rimosso alla termine del metodo Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception ex) { // handle the error } try { Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=monty&password=greatsqldb"); // Do something with the Connection } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } } }
Io i driver gli ho messi nella stesa cartella del sorgente .java, o non vanno messi li?codice:SQLException: No suitable driver found for jdbc:mysql://localhost/test?user=monty&password=greatsqldb SQLState: 08001 VendorError: 0
A parte che non sono riuscito ad impostare user e password per mysql sul MacOS perchè non mi prende il comando "mysql" (bisognerà modificare le variabile di sistema ma non so come), ma sto affrontando questa discussione già nel topic su mysql. Non riesco però a capire dove vanno messi i driver visto che non me li trova, o almeno così sembra dall'errore che mi da.


Rispondi quotando
