DBeaverを使ってMariaDBに接続し、動的Webプロジェクトで制作したプロジェクトでDBを使用したいと考えています。
プロジェクト内にDBを繋いだ状態?(画像の状態)まできたのですが、プロジェクトでMariaDBに接続する方法がわかりません。
servlet内で、以下のコードで接続を試しましたが、Class.forName()の段階で、ClassNotFoundExceptionが、Connectionの段階でNo suitable driver foundが出ます。
接続方法を教えていただきたいのですが、そもそも、画像までの段階があるのなら、簡単にプロジェクトと連携させる方法があるのではないかと思っています。
ただ、DBeaverの公式サイトや検索では見つけられなかったので、一旦Servletで接続を試みています。
以下のようにコードで直に書くのではなく、簡単な方法があれば、それも教えていただければと思います。
final String url = "jdbc:mariadb://localhost:3306/"; final String user = "root"; final String pass = ""; try { Class.forName("org.mariadb.jdbc.Driver"); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } try(Connection conn = DriverManager.getConnection(url,user,pass)) { System.out.println("成功"); } catch (SQLException e) { System.out.println("connect error"); e.printStackTrace(); }
以下加筆
cache.properties
#Mon Aug 26 11:16:50 JST 2019 gradle.version=5.4
他に二か所のディレクトリに、gc.propertiesファイルがありましたが空でした。
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <display-name>connecttest</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
あなたの回答
tips
プレビュー