JTable c/ MySQL com erro no comando SELECT

1 resposta
jtablejavajavascriptprogramaçãomysql
P

Alguém pode me ajudar? Não sei o que estou fazendo errado no meu código.

private void searchforclient() {
		try {
			Connection con = ConnectionWith.do_connection();
			String sql = "SELECT * FROM dados_senhas WHERE usuario LIKE ?";
			PreparedStatement stat = con.prepareStatement(sql);
			ResultSet rs = stat.executeQuery();
			DefaultTableModel dt =(DefaultTableModel)table_1.getModel();
			dt.setNumRows(0);
			while (rs.next()) {
				stat.setString(1, "%" + textField.getText() + "%");
				dt.addRow(new Object[] {rs.getString("id"), rs.getString("usuario"), rs.getString("senha"), rs.getBoolean("administrador")});
				
			}
			rs.close();
			con.close();
			
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
	}

E o erro que está dando é este: Tue Dec 24 03:38:27 BRST 2019 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. java.sql.SQLException: No value specified for parameter 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2265) at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2245) at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2175) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1995) at notebook.interfaces.SearchForClient.searchforclient(SearchForClient.java:48) at notebook.interfaces.SearchForClient.access$1(SearchForClient.java:43) at notebook.interfaces.SearchForClient$2.actionPerformed(SearchForClient.java:94) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
Diz que não há valores especificados para o parâmetro 1, porém no meu banco de dados, há sim.

1 Resposta

darlan_machado
  1. Você cria a query e diz a ela para esperar um parâmetro que irá substituir o ? ao final dela.
  2. Você constrói o statement
  3. Você executa o statement sem informar o bendito parâmetro.

O que eu não entendi foi isso:

Por que colocou aqui a linha que deveria estar logo abaixo da criação do statement?

Criado 24 de dezembro de 2019
Ultima resposta 24 de dez. de 2019
Respostas 1
Participantes 2