Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT TABLE_NAME, ORDINAL_POSITION,
- COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE
- FROM INFORMATION_SCHEMA.COLUMNS
- WHERE TABLE_SCHEMA = {YOUR_DB}
- ORDER BY TABLE_NAME, ORDINAL_POSITION;
- public class getColumnDataTypes
- {
- public static void main (String[] args) throws Exception
- {
- String driver = "com.mysql.jdbc.Driver";
- String connString = "jdbc:mysql://localhost:3300/DATABASE,USERNAME,PASSWORD";
- Class.forName(driver);
- Connection connection = DriverManager.getConnection(connString);
- Statement statement = connection.createStatement();
- //Query
- ResultSet resultSet = statement.executeQuery("SELCET * FROM table");
- ResultSetMetaData rsmd = resultSet.getMetaDate();
- //Get number of columns returned
- int numOfCols = rsmd.getColumnCount();
- //Print out type for each column
- for(int i=1; i<=numOfCols; ++i)
- {
- System.out.println("Column [" + i + "] data type: " + rsmd.getColumnTypeName(i));
- }
- //Close DB connection
- statement.close();
- connection.close();
- }
- }
Add Comment
Please, Sign In to add comment