Cześć mam problem z połączeniem do mysql. Przy wystąpieniu błędy otrzymuje ten komunkat...
Communication failure during handshake. Is there a server running on localhost:3308?
Używam strownika mm.mysql-2.0.7.
Gdy wchodzę do MySql przez MySql Command Line Client i wpisuje \status otrzymuje następujące wiadomości.
Connection id: 3
Current database:
Current user: root@localhost
SSL: Not in use
Using delimiter: ;
Server version: 4.1.12a-nt
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1
TCP port: 3308
Uptime: 37 min 59 sec
Threads: 1 Questions: 4 Slow queries: 0 Opens: 11 Flush tables: 1 Open tabl
es: 0 Queries per second avg: 0.002
Oto mój kod:
private void get_to_mysql() {
try {
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc//localhost:3308/wydatki";
Properties prop = new Properties();
prop.setProperty("user","root");
prop.setProperty("password","tygrysek");
con = DriverManager.getConnection(url,prop);
System.out.println("Udalo sie nawiazac połączenie z bazą danych");
stmt = con.createStatement();
String selectSQL = "select * from wydatki";
res = stmt.executeQuery(selectSQL);
while(res.next()) {
for(int i=0;i<=16;i++)
{
Table.setValueAt(res.getObject(1),i,0);
Table.setValueAt(res.getObject(2),i,1);
Table.setValueAt(res.getObject(3),i,2);
Table.setValueAt(res.getObject(4),i,3);
res.next();
}
}
con.close();
stmt.close();
res.close();
}
catch(ClassNotFoundException e) {
System.out.println("Problem z klasa");
System.out.println(e.getMessage());
}
catch(SQLException e) {
System.out.println("Problem z SQL");
System.out.println(e.getMessage());
e.printStackTrace();
}
}
e.printStackTrace() daje następujący rezultat:
java.sql.SQLException: Communication failure during handshake. Is there a server running on localhost:3308?
Communication failure during handshake. Is there a server running on localhost:3308?
at org.gjt.mm.mysql.MysqlIO.init(MysqlIO.java:337)
at org.gjt.mm.mysql.Connection.connectionInit(Connection.java:276)
at org.gjt.mm.mysql.jdbc2.Connection.connectionInit(Connection.java:89)
at org.gjt.mm.mysql.Driver.connect(Driver.java:167)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at wydatki.frame.get_to_mysql(frame.java:40)
at wydatki.frame.access$000(frame.java:12)
at wydatki.frame$1.actionPerformed(frame.java:80)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1766)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Pozdrawiam i prosze o pomoc.