Problema com insert

5 respostas
D

quando tento inserir, estou com o seguinte erro:

Exception in thread "main" java.sql.SQLException: Unknown initial character set index '48' received from server. Initial client character set can be forced via the 'characterEncoding' property.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
	at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2345)
	at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)
	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)
	at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at java.sql.DriverManager.getConnection(Unknown Source)
	at br.com.david.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:11)
	at br.com.david.dao.TesteDAO.<init>(TesteDAO.java:14)
	at br.com.david.teste.TestaInsere.main(TestaInsere.java:14)

TesteDAO.java

package br.com.david.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.com.david.bean.Teste;
import br.com.david.jdbc.ConnectionFactory;

public class TesteDAO {
	private Connection con;
	
	public TesteDAO() throws SQLException {
		this.con = ConnectionFactory.getConnection();
	}
	
	public void adiciona(Teste teste) throws SQLException {
		PreparedStatement stmt = this.con.prepareStatement("insert into teste (nome) values (?)");
		stmt.setString(1, teste.getNome());
		stmt.execute();
		stmt.close();
		con.close();
	}
}

ConnectionFactory.java

package br.com.david.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {
	public static Connection getConnection() throws SQLException {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			return DriverManager.getConnection("jdbc:mysql://localhost/teste", "root", "" );
		} catch(ClassNotFoundException e) {
			throw new SQLException(e.getMessage());
		}
	}
}

TesteInsere.java

package br.com.david.teste;

import java.sql.SQLException;

import br.com.david.bean.Teste;
import br.com.david.dao.TesteDAO;

public class TestaInsere {
	public static void main(String[] args) throws SQLException {
		
		Teste teste = new Teste();
		teste.setNome("david");
		
		TesteDAO dao = new TesteDAO();
		dao.adiciona(teste);
	}
}

5 Respostas

fabim

olha a linha 11 da sua classe ConnectionFactory e ve se consegue descobrir algo o.O

D

aparentemente não tem nada errado…

fabim

cara, dei uma googlada e vi q tem umonte de gente com problema parecido com o seu… alguns dizendo q era problema com maquinas IBM, outros q e a versao do driver… da um olhada la, cola isso aqui na procura e boa pesquisa =)

“Unknown initial character set index”

D

jpa procurei no google e li sobre os problemas, inclusive um forum alemão falou pra mudar o encode do mysql, eu mudei…mas não resolveu…por isso que postei aqui hehe

B

para quem usa o pacote XAMPP, isso aqui resolve

http://forum.java.sun.com/thread.jspa?threadID=780244

Criado 3 de janeiro de 2007
Ultima resposta 3 de fev. de 2007
Respostas 5
Participantes 3