Advertisement
Guest User

Untitled

a guest
Mar 14th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package jdbc_test;
  2. import java.sql.*;
  3. import java.util.Scanner;
  4. /**
  5. *
  6. * @author hp-admin
  7. */
  8. public class JDBC_Test
  9. {
  10.  
  11. /**
  12. * @param args the command line arguments
  13. */
  14. public static void main(String[] args)
  15. {
  16. // TODO code application logic here
  17. String tableName=null;
  18. Scanner input = new Scanner(System.in);
  19. int id=8;
  20. System.out.println("Enter the table name: ");
  21. tableName = input.nextLine();
  22. try
  23. {
  24. //step1 load the driver class
  25. // Class.forName("oracle.jdbc.driver.OracleDriver");
  26.  
  27.  
  28. Connection con = DriverManager.getConnection(
  29. "jdbc:oracle:thin:@localhost:1521:oracle12c", "system", "oracle12c");
  30.  
  31.  
  32. Statement stmt = con.createStatement();
  33.  
  34. // ResultSet rs = stmt.executeQuery("select * from "+tableName+"where id='"+id+"'");
  35. ResultSet rs = stmt.executeQuery("select * from "+tableName+"where id='"+id+"'");
  36. System.out.printf("%15s%15s","Name","ID");
  37. while (rs.next())
  38. {
  39. // System.out.println(rs.getString(1) + " " + rs.getString(2));
  40. // System.out.printf("n%15s%15S",rs.getString("name"),rs.getString("id"));
  41. System.out.printf("n%15s",rs.getString("name"));//,rs.getString("id"));
  42. }
  43.  
  44.  
  45. con.close();
  46. stmt.close();
  47. }
  48. catch (Exception e)
  49. {
  50. System.out.println(e);
  51. }
  52. }
  53. }
  54.  
  55.  
  56.  
  57. Enter the table name:
  58. t
  59. java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement