Eclipseで下記のコードを使用し、MariaDBへの接続を確認しているのですが、接続できません。
package db; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import org.mariadb.jdbc.internal.util.constant.Version; public class test1 { public static void main(String[] args) { Connection conn = null; Statement stmt = null; try { Class.forName("org.mariadb.jdbc.Driver"); System.out.println("Connector/J " + Version.version + "\n"); System.out.print("Connecting to DB..."); conn = DriverManager.getConnection( "jdbc:mariadb://localhost:8080/mysql", "root", ""); System.out.println(" done."); stmt = conn.createStatement(); String sql = "SELECT user,host FROM mysql.user"; ResultSet hrs = stmt.executeQuery(sql); while (hrs.next()) { String user = hrs.getString(1); String host = hrs.getString(2); System.out.println("User: " + user + "@'" + host + "'"); } } catch (SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { //finally block used to close resources try { if (stmt != null) { conn.close(); } } catch (SQLException se) {} // do nothing try { if (conn != null) { conn.close(); } } catch (SQLException se) { se.printStackTrace(); } //end finally try } //end try System.out.println("\nGoodbye!"); } }
コンソールには
Connector/J 2.7.3 Connecting to DB...java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=localhost)(port=8080)(type=master) : Could not connect to localhost:8080 : unexpected end of stream, read 0 bytes from 4 (socket was closed by server) Goodbye! at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73) at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:194) at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1394) at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:635) at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:150) at org.mariadb.jdbc.Driver.connect(Driver.java:89) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at db.test1.main(test1.java:22) Caused by: java.sql.SQLNonTransientConnectionException: Could not connect to localhost:8080 : unexpected end of stream, read 0 bytes from 4 (socket was closed by server) at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73) at org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory.create(ExceptionFactory.java:185) at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.createConnection(AbstractConnectProtocol.java:575) at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:1389) ... 6 more Caused by: java.io.EOFException: unexpected end of stream, read 0 bytes from 4 (socket was closed by server) at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacketArray(StandardPacketInputStream.java:249) at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacket(StandardPacketInputStream.java:218) at org.mariadb.jdbc.internal.com.read.ReadInitialHandShakePacket.<init>(ReadInitialHandShakePacket.java:89) at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.createConnection(AbstractConnectProtocol.java:527) ... 7 more
と表示されます。
接続させるにはどうすればよろしいでしょうか。
回答1件
あなたの回答
tips
プレビュー