I am learning JAVA programming language. How can we get the details for printing the user’s details at run time using JDBC connectivity? Anybody knows any suitable code for that? Please reply me as soon as possible.
I am learning JAVA programming language. How can we get the details for printing the user’s details at run time using JDBC connectivity? Anybody knows any suitable code for that? Please reply me as soon as possible.
Here is the coding for JDBC Connectivity to retrieve users details:
Code:import java.sql.*; import java.io.*; public class JDBCConnection { public static void main(String args[]) { Connection conn; Statement stmt; ResultSet rs; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(Exception e) { e.printStackTrace(); } try { conn=DriverManager.getConnection("jdbc:odbc:employeedsn"); stmt=conn.createStatement(); rs=stmt.executeQuery("select * from emp"); System.out.println("EId Ename DOB Dept Salaryn"); while(rs.next()) { System.out.println(+rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4)+" "+rs.getInt(5)); } stmt.close(); conn.close(); } catch(Exception e) { e.printStackTrace(); } } }
Try this:
Code:import java.sql.*; import java.io.*; public class Employeedetails { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:employeeds"); Statement st=con.createStatement(); ResuleSet rs=st.executeQuery("select * from emp"); System.out.println("EId Ename Salaryn"); while(rs.next()) { System.out.println(+rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)); } st.close(); con.close(); } catch(Exception e) { e.printStackTrace(); } } }
Bookmarks