import java.sql.Statement; import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; public class jdbcselect { public static void main(String[] args) { Connection conn = null; Statement st = null; try{ conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "system", "1808"); st = conn.createStatement(); ResultSet rs1 = st.executeQuery("select * from employee"); while(rs1.next()) { int id = rs1.getInt(1); String name = rs1.getString(2); String job = rs1.getString(3); int mgr = rs1.getInt(4); Date date = rs1.getDate(5); int sal = rs1.getInt(6); int com = rs1.getInt(7); int deptno = rs1.getInt(8); System.out.println( id + "," + name + "," + job + "," + mgr + "," + date + "," + sal + "," + com + "," + deptno); } }catch(SQLException e) { e.printStackTrace(); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter