开发者

JDBC MYSQL Connection without specifying database?

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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜