Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. package edu.uic.ids401.util;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.Scanner;
  8.  
  9. public class DBaseMain {
  10.  
  11.    
  12.     public static void main(String[] args) {
  13.        
  14.         String userName=null;
  15.         String password=null;
  16.         String dbmsServer=null;
  17.         String dbmsType=null;
  18.         String dbScheme=null;
  19.  
  20.        
  21.         Scanner keyboard=new Scanner(System.in);
  22.         System.out.println("What is your username?");
  23.         userName= keyboard.next();
  24.         System.out.println("What is your password?");
  25.         password= keyboard.next();
  26.         System.out.println("What is the dbmsServer name");
  27.         dbmsServer= keyboard.next();
  28.         System.out.println("What is your dbmsType");
  29.         dbmsType= keyboard.next();
  30.         System.out.println("What is your dbscheme");
  31.         dbScheme= keyboard.next();
  32.         System.out.print("Enter file name:");
  33.         String fileName=keyboard.next();
  34.         Scanner inputStream=null;
  35.        
  36. String url = "jdbc:"+dbmsType+"://"+dbmsServer+":3306"+"/"+dbScheme;   
  37. DBase dbase= new DBase("com.mysql.jdbc.Driver",url,userName,password);
  38.  
  39.  
  40. ResultSet rs=null;
  41. System.out.print("What is your query?");
  42. String query=keyboard.next();
  43. rs = dbase.executeSQLdmlQuery(keyboard.nextLine());
  44.  
  45. try {
  46.     int numofCol= rs.getMetaData().getColumnCount();
  47.     System.out.println(numofCol);
  48.     } catch (SQLException e1) {
  49.     e1.printStackTrace();
  50.     }
  51.  
  52.     try {
  53.     rs.last();
  54.     int rows = rs.getRow();
  55.     } catch (SQLException e1) {
  56.    
  57.     e1.printStackTrace();
  58.     }
  59.  
  60.  
  61. try
  62. {
  63.     inputStream=new Scanner(new File(fileName));
  64.  
  65. }
  66.  
  67. catch(FileNotFoundException e)
  68. {
  69.     System.out.println("Error opening the file "+ fileName);
  70.     System.exit(0);
  71. }
  72.  
  73. while(inputStream.hasNextLine())
  74. {
  75. String line=inputStream.nextLine();
  76. System.out.println(line);
  77. }
  78. inputStream.close();
  79. }
  80.    
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement