Last active
June 20, 2017 21:33
-
-
Save nirbhayc/7555927c4031280ed41dbd3fa21ae94d to your computer and use it in GitHub Desktop.
(Blog) CLASSNOTFOUNDEXCEPTION in MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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