JDBC MYSQL Connection without specifying database?

我是研究僧i 提交于 2019-12-11 11:45:06

问题


I am using the SphinxQL MySQL client which stores indexes as "tables" but has no real notion of a "database"...One specifies the port (9306 in my case) at which the sphinx mysql instance listens and in theory should be able to communicate as normal.

I have the following test code:

import java.sql.*;

public class Dbtest {
    public static void main (String[] args) {

    try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:9306",
                         "user","password");
        con.setReadOnly(true);
        Statement stmt = con.createStatement();    
        ResultSet res = stmt.executeQuery("SELECT * from index_turned_table");

        while (res.next()) {
            String stuff1 = res.getString(1);
            String stuff2 = res.getString(2);
            System.out.println("Adding " + stuff1);
            System.out.println("Adding " + stuff2);    
        }

        res.close();
        stmt.close();
        con.close();
    }
    catch(Exception e)
    {
        System.out.println (e);
    }
}

Upon execution, the code just hangs and does nothing and doesn't print out an exception. What are useful things I can do to figure this out or if any one has direct experience what might be going on?


回答1:


This work with 1.10-beta http://www.olegsmith.com/2010/12/scalalift-sphinxql.html and not work with 2.0.1-beta. Use mysql-connector-java 5.1.15.




回答2:


Your SphinxQL instance is listening on port 9306. Your MySQL is listening on some other port, likely on the default 3306. You can use MySQL JDBC driver to connect to MySQL, but you cannot use it to connect to SphinxQL. It just doesn't understand JDBC driver communication protocol.



来源:https://stackoverflow.com/questions/6371643/jdbc-mysql-connection-without-specifying-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!