Skip to content

Instantly share code, notes, and snippets.

@nirbhayc
Last active June 20, 2017 21:33
Show Gist options
  • Save nirbhayc/7555927c4031280ed41dbd3fa21ae94d to your computer and use it in GitHub Desktop.
Save nirbhayc/7555927c4031280ed41dbd3fa21ae94d to your computer and use it in GitHub Desktop.
(Blog) CLASSNOTFOUNDEXCEPTION in MySQL
/**
Get server version.
*/
import java.sql.*;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.*;
public class Version {
public static void main (String args[]) {
Version obj = new Version();
obj.getVersion();
}
public void getVersion() {
/* it is important to place the code below under 'try' */
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:13000/test","root","");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT VERSION()");
while(rs.next())
{
System.out.println(rs.getString(1));
}
} catch(Exception e) { System.out.println(e); }
} //end of getVersion()
} //end of Version Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment