亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

執行execute語句報錯(sex字段是枚舉型的)

StudentDao里的插入方法
public?void?addStudent(Student?student)?throws?SQLException{
		Connection?conn=DBUtil.getConnection();
		String?sql="insert?student"+
		"(number,name,sex,age,birthday)"+
		"values("+
		"?,?,?,?,?)";
		PreparedStatement?ps=conn.prepareStatement(sql);
		ps.setString(1,?student.getNumber());
		ps.setString(2,?student.getName());
		ps.setString(3,?student.getSex());
		ps.setInt(4,?student.getAge());
		ps.setDate(5,?new?Date(student.getBirthday().getTime()));
		ps.execute();
		conn.close();
	}
action里的
public?class?StudentAction?{
	public?static?void?main(String[]?args)?throws?Exception?{
		StudentDao?sd=new?StudentDao();
		Student?stu=new?Student();
		stu.setNumber("140521203");
		stu.setName("張三");
		stu.setAge(19);
		stu.setSex("男");
		stu.setBirthday(new?SimpleDateFormat("yyyy-MM-dd").parse("1996-03-20"));
		sd.addStudent(stu);
		List<Student>?sl=sd.query();
		for?(Student?student?:?sl)?{
			System.out.println(student.toString());
		}
	}
}

控制臺報錯:

Exception?in?thread?"main"?java.sql.SQLException:?Could?not?retrieve?transation?read-only?status?server
	at?com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
	at?com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
	at?com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
	at?com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
	at?com.mysql.jdbc.SQLError.createSQLException(SQLError.java:951)
	at?com.mysql.jdbc.SQLError.createSQLException(SQLError.java:941)
	at?com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3936)
	at?com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3907)
	at?com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2408)
	at?com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
	at?com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
	at?china_mozhu.dao.StudentDao.addStudent(StudentDao.java:28)
	at?china_mozhu.action.StudentAction.main(StudentAction.java:21)
Caused?by:?java.sql.SQLException:?Unknown?system?variable?'tx_read_only'
	at?com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
	at?com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
	at?com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
	at?com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
	at?com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
	at?com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2809)
	at?com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2758)
	at?com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1612)
	at?com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3930)
	...?6?more


正在回答

1 回答

額,已找到原因,connector和MySQL版本不匹配

1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

執行execute語句報錯(sex字段是枚舉型的)

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號