世界震撼.dev

いつか世界を驚かせるためのメモ

MySQL

JDBCでテーブル一覧を取得

try(Connection conn = DriverManager.getConnection(url, user, password); ResultSet rs = conn.getMetaData().getTables(null, null, "%", null); ){ final StringBuilder sb = new StringBuilder( ); while( rs.next( ) ){ sb.append( rs.getString( 3 )…

JDBCでファイルからデータを読み込んでテーブルに挿入

File file = new File( ABSOLUTE_FILEPATH ); try( BufferedReader br = Files.newBufferedReader( Paths.get( file.getAbsolutePath( ) ) , StandardCharsets.UTF_8 ) ){ for( String line; ( line = br.readLine( ) ) != null; ){ stmt.executeUpdate( "in…

JDBCでテーブルのカラム情報を取得する

try{ if( stmt.execute( "describe TABLENAME" ) ){ StringBuilder sb = new StringBuilder( ); ResultSet describe = stmt.getResultSet( ); while( describe.next( ) ){ for( int i = 1; i <= describe.getMetaData( ).getColumnCount( ); i++ ){ sb.appen…