get Database Table Name from Class name - Java java.sql

Java examples for java.sql:Table

Description

get Database Table Name from Class name

Demo Code


//package com.java2s;

public class Main {
    public static String getTableName(String className) {
        StringBuffer tableName = new StringBuffer();
        for (int i = 0; i < className.length(); i++) {
            char character = className.charAt(i);
            if (Character.isLowerCase(character)) {
                tableName.append(character);
            } else {
                if (i != 0) {
                    tableName.append("_");
                }//w  w w . j a v a2s .co  m
                tableName.append(Character.toLowerCase(character));
            }
        }
        return tableName.toString();
    }
}

Related Tutorials