import java.sql.Statement; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Date; public class jdbcInsert { public static void main(String[] args) throws ClassNotFoundException,SQLException{ Connection conn = null; Statement st = null; try { conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE", "system", "1808"); st = conn.createStatement(); int row= st.executeUpdate("Insert into employee values (7990,'manish','salesman',7755,TO_DATE('17-DEC-24', 'DD-MON-RRRR'),1000,30,25)"); ResultSet rs1 = st.executeQuery("select * from employee"); while (rs1.next()) { int id=rs1.getInt(1); String ename = rs1.getString(2); String job = rs1.getString(3); int mgr = rs1.getInt(4); Date hiredate = rs1.getDate(5); int sal = rs1.getInt(6); int com = rs1.getInt(7); int deptno = rs1.getInt(8); System.out.println(id+" "+ename+" "+job+" "+mgr+" "+hiredate+" "+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