import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import com.mysql.jdbc.Connection; import com.mysql.jdbc.Statement; public class Main { public static void main(String[] args) { Connection conn = null; Statement stmt = null; ResultSet rs = null; String connectionString = "jdbc:mysql://localhost/lightbox?user=root&password="; try { // 接続文字列で接続 conn = (Connection) DriverManager.getConnection(connectionString); String query = "select * from 社員マスタ"; stmt = (Statement) conn.createStatement(); rs = stmt.executeQuery(query); String scode; String sname; while( rs.next() ) { scode = rs.getString(1); sname = rs.getString(2); System.out.println("番号:" + scode + " " + sname); scode = rs.getString("社員コード"); sname = rs.getString("氏名"); System.out.println("列名:" + scode + " " + sname); } rs.close(); stmt.close(); // 接続を閉じる conn.close(); } catch (SQLException e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } System.out.println("終了"); } }