Advertisement
Guest User

Untitled

a guest
Feb 24th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.Statement;
  3. import java.sql.ResultSet;
  4. import java.sql.DriverManager;
  5.  
  6. public class ExcelReader {
  7.  
  8. public static void main( String [] args ) {
  9.  
  10. Connection c = null; Statement stmnt = null;
  11.  
  12. try
  13. {
  14. Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
  15.  
  16. //using DSN connection. Here qa is the name of DSN
  17. //c = DriverManager.getConnection( "jdbc:odbc:qa", "", "" );
  18.  
  19. //using DSN-less connection
  20. c = DriverManager.getConnection( "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=C:/Users/Μιχάλης/Documents/mike1.xls");
  21.  
  22.  
  23. stmnt = c.createStatement();
  24. String query = "select * from [Ledis$] ;";
  25. ResultSet rs = stmnt.executeQuery( query );
  26. while( rs.next() )
  27. {
  28. System.out.println(rs.getString(1));
  29.  
  30. }
  31. }
  32. catch( Exception e )
  33. {
  34. //System.err.println( e );
  35. }
  36. finally
  37. {
  38. try
  39. {
  40. stmnt.close();
  41. c.close();
  42. }
  43. catch( Exception e )
  44. {
  45. System.err.println( e );
  46. }
  47. }
  48. }
  49. }
  50.  
  51. 90-02-00-0000-2000
  52. 90-02-00-0000-2400
  53. 90-02-00-0000-2500
  54. 90-02-00-0000
  55. 90-02-00
  56. 90-02
  57. 90-06-00-0000-6000
  58. 90-06-00-0000-6100
  59. 90-06-00-0000-6200
  60. 90-06-00-0000-6300
  61. 90-06-00-0000-6400
  62. 90-06-00-0000-6500
  63. 90-06-00-0000-6600
  64. 90-06-00-0000
  65. 90-06-00
  66. 90-06
  67. null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement