1 24 25 package com.mckoi.database.jdbc; 26 27 import java.io.*; 28 import java.sql.*; 29 import java.net.*; 30 31 36 37 class TCPStreamDatabaseInterface extends StreamDatabaseInterface { 38 39 42 private String host; 43 44 47 private int port; 48 49 52 private Socket socket; 53 54 57 TCPStreamDatabaseInterface(String host, int port) { 58 this.host = host; 59 this.port = port; 60 } 61 62 65 void connectToDatabase() throws SQLException { 66 if (socket != null) { 67 throw new SQLException("Connection already established."); 68 } 69 try { 70 socket = new Socket(host, port); 72 setup(socket.getInputStream(), socket.getOutputStream()); 74 } 75 catch (IOException e) { 76 throw new SQLException(e.getMessage()); 77 } 78 } 79 80 } 81 | Popular Tags |