前提・実現したいこと
Eclipse,Springを使ってJAVAの勉強をしている初心者です。
元々、受講していた通信教育の課題がDBを使用しておらず、
内部にテーブルを保持している構造だったので、それを
MySQL,jDBCで外部化しようとしています。
ネット等で参考となるプログラムのコードを追記したのですが、
以下のようなエラーメッセージが発生しました。
諸先輩方、程度の低い質問かとは思いますが、何とぞご教授ください
ますよう、お願いいたします。
発生している問題・エラーメッセージ
HTTPステータス 500 - Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: The server time zone value '���� (�W����)' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
type 例外レポート
メッセージ Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: The server time zone value '���� (�W����)' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
説明 The server encountered an internal error that prevented it from fulfilling this request.
例外
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: The server time zone value '���� (�W����)' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
該当のソースコード
◆Controller.java
import java.util.List;
import java.util.Map;
/**start */
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/*e n d/
@Controller
@RequestMapping(value = "/book")
public class AddressBookController {
private static final String INIT = "init";
private static final String REFER = "refer";
private static final String UPDATE = "update";
private static final String LIST = "list";
private static final String INIMSG = "従業員番号を入力してください";
private static final String REFMSG = "情報が取得できました";
private static final String UPDMSG = "情報を更新してください";
private static final String ERRMSG = "該当するデータはありません";
/**start */
@Autowired
private JdbcTemplate jdbcTemplate;
/*e n d/
@RequestMapping(value = "/start") public String init(AddressBookForm form, Model model) {
/**start */
System.out.println("step1");
List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from unit02.addressbook");
model.addAttribute("data", list.get(0).get("name") );
/*e n d/
model.addAttribute("message", INIMSG);
return INIT;
}
@RequestMapping(params = "reference") public String refer(AddressBookForm form, Model model) { Employee employee = RecordManager.selectEmployee(form.getId()); if (employee != null) { form.setName(employee.getName()); form.setPhone(employee.getPhone()); form.setAddress(employee.getAddress()); model.addAttribute("message", REFMSG); return REFER; } else { model.addAttribute("message", ERRMSG); return INIT; } } @RequestMapping(params = "toInit") public String toInit(AddressBookForm form, Model model) { model.addAttribute("message", INIMSG); return INIT; } @RequestMapping(params = "update") public String update(AddressBookForm form, Model model) { Employee employee = RecordManager.selectEmployee(form.getId()); if (employee != null) { form.setName(employee.getName()); form.setPhone(employee.getPhone()); form.setAddress(employee.getAddress()); model.addAttribute("message", UPDMSG); return UPDATE; } else { model.addAttribute("message", ERRMSG); return INIT; } } @RequestMapping(params = "reflection") public String reflection(AddressBookForm form, Model model) { Employee employee = new Employee(form.getId(), form.getName(), form.getPhone(), form.getAddress()); RecordManager.updateEmployee(employee); model.addAttribute("message", INIMSG); return INIT; } @RequestMapping(params = "list") public String list(Model model) { List<Employee> employeeList = RecordManager.getEmployeeList(); model.addAttribute("employeeList", employeeList); model.addAttribute("employeeCount", employeeList.size()); return LIST; }
◆init.jsp
<%@ page session="false" language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.time.LocalDate"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
◆servlet-context.xlmに追記
<!-- start --><!-- end --><beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" > <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" /> <beans:property name="url" value="jdbc:mysql://127.0.0.1:3306/unit02" /> <beans:property name="username" value="root" /> <beans:property name="password" value="mippy333" /> </beans:bean> <beans:bean class="org.springframework.jdbc.core.JdbcTemplate"> <beans:constructor-arg ref="dataSource" /> </beans:bean>
試したこと
MySQLのサービスは起動を確認しています。
MySQLのjdbcもeclipseのビルドパスに外部jarとして登録しました。
補足情報(FW/ツールのバージョンなど)
MySQL(jdbc) 8.0.16
Eclipse4.5 Mars Pleiades
回答1件
あなたの回答
tips
プレビュー