0
How do I pass one Char
to the Bank?
Error
Exception in thread "main" java.sql.SQLException: ORA-12899: valor muito grande para a coluna "SYSTEM"."USUARIO"."TP_SEXO" (real: 2, máximo: 1)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:208)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1046)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3613)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3714)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1378)
at br.com.younews.dao.UsuarioDao.adiciona(UsuarioDao.java:33)
at br.com.younews.teste.TesteUsuarioDao.main(TesteUsuarioDao.java:20)
my code:
package br.com.younews.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import br.com.younews.beans.Usuario;
import br.com.younews.conexao.ConexaoFactory;
public class UsuarioDao {
private Connection conn;
private List<Usuario> user = new ArrayList<Usuario>();
public UsuarioDao() throws Exception {
this.conn = new ConexaoFactory().getConnection();
}
public Usuario adiciona(Usuario usuario) throws SQLException{
String sql = "INSERT INTO USUARIO (EMAIL_USUARIO, NM_USUARIO, SENHA_USUARIO, TP_SEXO, DT_NASCIMENTO, FOTO_USUARIO, NM_LOCALIZACAO, NM_SOBRENOME, NM_NOME) VALUES (?,?,?,?,?,?,?,?,?)";
PreparedStatement st = conn.prepareStatement(sql);
st.setString(1, usuario.getEmail());
st.setString(2, usuario.getNmUsuario());
st.setString(3, usuario.getSenha());
st.setInt(4, usuario.getSexo());
st.setString(5, usuario.getDataNasc());
st.setString(6, usuario.getFotoPerfil());
st.setString(7, usuario.getLocalizacao());
st.setString(8, usuario.getNome());
st.setString(9, usuario.getSobrenome());
st.execute();
st.close();
return usuario;
}
public List<Usuario> listarUsuario() throws Exception{
List<Usuario> user = new ArrayList<Usuario>();
PreparedStatement p = conn.prepareStatement("SELECT P.CD_USUARIO FROM USUARIO P LEFT JOIN USUARIO_AMIGO E ON E.USUARIO_CD_USUARIO1 = E.CD_AMIGO");
ResultSet rs = p.executeQuery();
while(rs.next()){
Usuario usuario = new Usuario();
usuario.setIdLogin(rs.getString("CD_USUARIO"));
usuario.setNmUsuario(rs.getString("NM_USUARIO"));
}
rs.close();
p.close();
return user;
}
}
What is the type of data in the database?
– Jéf Bueno
TP_SEXO CHAR(1 BYTE)
– Guilherme Almeida
Pretty sure if you switch to
CHAR(1 CHAR)
it’ll work. you can try it?– Jéf Bueno
To tag is SQL server, but the error is Oracle. Can fix the tag?
– Maniero
Jbueno, it worked, I switched to CHAR(2 CHAR), but my doubt, I passed as "int" because I do not know how to pass a char, but in the bank the correct one should not be 1?
– Guilherme Almeida
fixed man :)
– Guilherme Almeida
Ahhhhhh, the question is
set
ofPreparedStatement
?– Jéf Bueno
that same guy
– Guilherme Almeida