Ir para conteúdo
  • 0

Dúvida - SQL


zAth

Pergunta

O problema que ocorre é que o valor que eu guardo no sql, simplesmente desaparece

 

Estou usando isso para guardar

 

 

    public static void update(Chest chest) {
        openConnection();

        String owner = chest.getDono();
        Integer id = chest.getId();
        String serializedIcon = chest.getSerializedIcon();
        String serializedContents = chest.getSerializedContents();

        try {
            PreparedStatement statement = getConnection().prepareStatement("UPDATE chests SET serializedicon=? AND serializedcontents=? WHERE owner=? AND id=?;");
            statement.setString(1, serializedIcon);
            System.out.println("SerializedIcon - " + serializedIcon); //
// "SerializedIcon - a0000g002d5i0053dd5n6aoric5j78ejicli5upjcdtrma sg1002k6rrldpq020g00p262rb1ctig0000"
            statement.setString(2, serializedContents);
            statement.setString(3, owner);
            statement.setInt(4, id);
            statement.executeUpdate();
            statement.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeConnection();
        }
    } 

 

 

 

Quando pego os valores

 

 

    public static void load() {
        openConnection();
        try {
            PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM chests;");
            ResultSet rs = statement.executeQuery();
            while(rs.next()){

                String owner = rs.getString("owner");
                Integer id = rs.getInt("id");
                String serializedIcon = rs.getString("serializedicon");
                System.out.println("SerializedIcon - " + serializedIcon); //
// "SerializedIcon - 0"
                String serializedContents = rs.getString("serializedcontents");

                new Chest(owner, id, serializedIcon, serializedContents);
            }
            statement.close();
            rs.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeConnection();
        }
    } 

 

 

 

estou criando a tabela assim

 

 

    public static void createTable() {
        openConnection();
        try {
            PreparedStatement sql = connection.prepareStatement("CREATE TABLE IF NOT EXISTS chests(owner varchar(255), id tinyint, serializedicon varchar(255), serializedcontents varchar(255));");
            sql.executeUpdate();
            sql.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            closeConnection();
        }
    } 

 

 

 

Alguém sabe porque isso está acontecendo?

Não sei se é porque varchar(255) não serve aqui, mas o que eu estou guardando só tem 82 caracteres ..

Ou se estou pegando mal os valores da db :/

 

(sqlite)

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...