escrevi o seguinte codigo para tentar fazer um insert nao esta dando certo, gostaria de aprender mais sobre jdbc, gostaria de saber se tem algum tutorial para aprender fazer cadastros com telas tipo swing algo assim obrigado
public class Insert {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
String ipMaquina = "localhost";
String nomeBanco = "mysql";
String usuario = "root";
String senha = "diego123";
Connection connection = DriverManager.getConnection("jdbc:mysql://"+ipMaquina+"/"+nomeBanco+"?user="+usuario+"&password="+senha);
Statement statement = connection.createStatement();
String nome = "Diego";
String email = "[email removido]";
String telefone = "34339052";
String queryInsert = "insert into contatos values = "+nome+email+telefone;
int update = statement.executeUpdate(queryInsert);
if(update != 0){
System.out.println("Operacao realizada com sucesso!");
System.out.println(queryInsert);
System.out.println("-----------------------");
}
statement.close();
connection.close();
}
}
da o seguinte erro : Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= [email protected]' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485)
at net.cadastro.Insert.main(Insert.java:33)
