Guest User

Untitled

a guest
May 19th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package connection;
  2.  
  3.  
  4. import java.sql.*;
  5. public class Connection {
  6.  
  7.  
  8. public static void main(String[] args) throws Exception
  9. {
  10. Connection con1=null;
  11. String c="oracle.jdbc.driver.OracleDriver";
  12. Class.forName(c);
  13. String url="jdbc:oracle:thin:@LAPTOP-1CQ5FAGB:1521:XE";
  14. String user="system";
  15. String passwd="srpnk";
  16. con1=(Connection) DriverManager.getConnection("jdbc:oracle:thin:@LAPTOP-1CQ5FAGB:1521:XE","system","srpnk");
  17. System.out.println("connected");
  18. }
  19.  
  20. }
  21.  
  22. Exception in thread "main" java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection cannot be cast to connection.Connection
  23. at connection.Connection.main(Connection.java:17)
  24. C:UsersNandhiniAppDataLocalNetBeansCache8.2executor-snippetsrun.xml:53: Java returned: 1
  25. BUILD FAILED (total time: 0 seconds)
  26.  
  27. public class Connection { // <-- This is a bad idea
  28.  
  29. public static void main(String[] args) throws Exception
  30. {
  31. Connection con1=null;
  32. // ...
  33. con1=(Connection) DriverManager.getConnection("jdbc:oracle:thin:@LAPTOP-1CQ5FAGB:1521:XE","system","srpnk");
  34. System.out.println("connected");
  35. }
Add Comment
Please, Sign In to add comment