beppegrillo
21-01-2005, 14:28
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
/*
* 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 :)
Error accessing DB
Error code is : 0
Error message is :No suitable driver
/*
* 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 :)