Olá preciso dee um help. Pegeui este código em um tutorial. Apenas para estudar como fazer a conexão.
Bem está dando errado.
Já baixei os drivers de acesso.
O que pode estar ocorrendo ?
import java.sql.*;
public class TestQuery {
public TestQuery () {
}
public static void main(String args[]) {
String url="jdbc:MySQL://ipmaq/banco";
Connection con;
String query = "comando";
Statement stmt;
try {
Class.forName("jdbc.mysql.jdbcMysqlDriver");
}
catch (java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
System.out.println("Trying to connect...");
con = DriverManager.getConnection (url, "root", "xxxxxxx");
System.out.println("connected!");
stmt = con.createStatement();
ResultSet result = stmt.executeQuery(query);
while (result.next()) {
String name = result.getString(1) + " " + result.getString(2);
System.out.println(name);
}
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.print("SQLException: ");
System.err.println(ex.getMessage());
}
}
}
Obrigado.