I build the code below but when I enter the data the system has an error.
package tarefaBD;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
public class Teste {
public static void main(String[] args) throws Exception {
Pessoa inserirpessoa = new Pessoa();
Scanner input = new Scanner(System.in);
try {
Connection conexao = DriverManager.getConnection("jdbc:mysql://localhost:3306/Tarefa4.2", "root", "14725800");
System.out.println("Digite o nome: ");
String nome = input.nextLine();
inserirpessoa.setNome(nome);
System.out.println("Digite a idade: ");
int idade = input.nextInt();
inserirpessoa.setIdade(idade);
System.out.println("Digite o endereço: ");
String endereco = input.nextLine();
inserirpessoa.setEndereço(endereco);
PreparedStatement stmt = conexao.prepareStatement("INSERT INTO pessoa(nome, idade, endereço) VALUES ( ?, ?, ?)");
stmt.setString(1, nome);
stmt.setInt(2, idade);
stmt.setString(3, endereco);
stmt.execute();
ResultSet rs = stmt.executeQuery("Select * from pessoa");
System.out.println("Pessoa no Banco de Dados: ");
while (rs.next()) {
System.out.println(rs.getString(nome));
System.out.println(rs.getInt(idade));
System.out.println(rs.getString(endereco));
}
System.out.println("Fim da leitura do banco de dados.");
conexao.close();
rs.close();
stmt.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
}
Error displayed on console:
Sat May 20 14:42:40 BRT 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Digite o nome: rogerio Digite a idade: 41 Digite o endereço: Pessoa no Banco de Dados: java.sql.SQLException: Column 'rogerio' not found. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1077) at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5192) at tarefaBD.Teste.main(Teste.java:53)