[MySQL][ODBC 5.1 Driver][mysqld-5.5.11]No database selected
Não consigo fazer funcionar, aparecer esse erro, sei que deve ser um erro banal, mas to começando.
Valeu!
import javax.swing.JOptionPane;
public class ConexaoDB {
public ConexaoDB() {
}
private String FonteDB, Usuario, Senha, Comando;
private Connection Conexao;
public ConexaoDB(String _FonteDB, String _Usuario, String _Senha, String _Comando) {
this.FonteDB = _FonteDB;
this.Usuario = _Usuario;
this.Senha = _Senha;
this.Comando = _Comando;
Conectar();
}
public void Conectar() {
String fonte = "jdbc:odbc:" + getFonteDB();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
setConexao(DriverManager.getConnection(fonte, getUsuario(), getSenha()));
Statement stm = getConexao().createStatement();
stm.executeUpdate(Comando);
System.out.println(Comando);
} catch (ClassNotFoundException e) {
System.out.println(e.getMessage());
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
package testeconexao2;
class usarComandos {
public static void main(String args[]) {
String LinhaSQL = "insert into turmas values(";
try {
ConexaoDB com = new ConexaoDB("AcessoDB", "root", "123", "insert into turmas values(1,'Sexta',2,2,'M')");
} catch (Exception e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}