Estou levou a maior surra ao tentar acabar uma janela de autenticacao de usuarios, estou com problemas na parte de consultar os dados enviados, ele esta dando o erro de “java.sql.DataTruncation: Data truncation”
ai vai o bendito codigo, para quem alguem puder me ajudar, desde de ja agradeço, novato sofre hein!!!
public void actionPerformed(ActionEvent e)//acao para o botao Ok
{
try
{
Class.forName(driver);
conexao = DriverManager.getConnection (url, username, passwd);
PreparedStatement pstm = conexao.prepareStatement("Select nome, senha from pessoal where nome = ? and senha = ?");
pstm.setString(1,"user");
pstm.setString(2,"password");
ResultSet rst = pstm.executeQuery();
if (rst.next()) {
JOptionPane.showMessageDialog(null, "Nome de arquivo inválido",
"Nome de arquivo inválido", JOptionPane.ERROR_MESSAGE);
// foram encontrados dados
}
else {
// nenhum dado foi encontrado
}
}
catch ( ClassNotFoundException cnfex)
{
System.err.println("Falha ao carregar Driver");
cnfex.printStackTrace();
System.exit(1);
}
catch (SQLException sqlex) {
System.err.println ("Impossivel Conectar");
sqlex.printStackTrace();
System.exit(1); //termina o processo
}
}
});
no trecho no resultset no if, quero emitir uma mensagem caso o login e senha estaejam errados e pedir para redigitar, os campos sao user um JTextField e o password é um JPasswordField.
Nao ha nenhum motivo aparente para o erro ocorrer. Se voce passar uma string menor o erro tmb ocorre? (passe um unico caracter, para efeito de testes).
Quando o banco de dados / driver de conexao que voce esta usando?
Impossivel Conectar
java.sql.DataTruncation: Data truncation
at org.firebirdsql.jdbc.FBStringField.setString(FBStringField.java:291)
at org.firebirdsql.jdbc.FBPreparedStatement.setString(FBPreparedStatement.java:210)
at Autenticacao$1.actionPerformed(Autenticacao.java:57)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$ForwardActionEvents.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 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.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)