Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Note:</em> This was originally a comment but got too long. It seems people see NFE and guess it's port that's null. Which is misleading. Here is a WORKING code showing port is not necessary. Please avoid misleading answers.</p> <pre><code> try { Class.forName("com.mysql.jdbc.Driver"); String sourceURL = "jdbc:mysql://localhost/sodb"; Connection conn = DriverManager.getConnection(sourceURL, "naishe", "p2ssword"); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select count(*) from test_tab"); while(rs.next()){ System.out.println(rs.getString(1)); } } catch(ClassNotFoundException cnfe) { System.err.println(cnfe); } catch(SQLException sqle) { System.err.println(sqle); } </code></pre> <p>It prints <code>3</code> (which is number of records in the table test_tab) correctly.</p> <hr> <p>If you are using <em>standard driver</em>, you <strong>do not need port</strong>, it defaults to 3306! See here <a href="http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-configuration-properties.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-configuration-properties.html</a></p> <blockquote> <p>JDBC URL Format</p> <p>The JDBC URL format for MySQL Connector/J is as follows, with items in square brackets ([, ]) being optional:</p> <p><code> jdbc:mysql://[host][,failoverhost...]<strong>[:port]</strong>/[database] » [?propertyName1][=propertyValue1][&amp;propertyName2][=propertyValue2]... </code></p> <p>If the host name is not specified, it defaults to 127.0.0.1. <strong>If the port is not specified, it defaults to 3306, the default port number for MySQL servers.</strong> </p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload