6
public class ODBCServer {
7
private Connection connection;
9
private boolean checkForWarning (SQLWarning warn) {
12
// If a SQLWarning object was given, display the
13
// warning messages. Note that there could be
14
// multiple warnings chained together
17
System.out.println ("\n *** Warning ***\n");
19
while (warn != null) {
20
System.out.println ("SQLState: " +
22
System.out.println ("Message: " +
24
System.out.println ("");
25
warn = warn.getNextWarning ();
29
} catch(Exception e) {
34
public ODBCServer(String dbName) {
36
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
38
connection = DriverManager.getConnection("jdbc:odbc:NTOP");
39
checkForWarning(connection.getWarnings());
40
//connection.setAutoCommit(true); // Automatic transaction commitment
41
} catch (Exception e) {
47
public void executeStatement(String statement) {
48
PreparedStatement stmt;
52
stmt = connection.prepareStatement(statement); // Insert record in the HostInfo table
53
rc = stmt.executeUpdate();
54
stmt.close(); // Close the statement
55
} catch(Exception ex) {
61
public static void main(String args[])
65
ODBCServer odbcServer;
66
DatagramSocket socket = null;
69
System.out.println("Starting up...");
72
socket = new DatagramSocket(4000);
73
} catch (Exception e) {
78
buffer = new byte[bufLength];
79
pkt = new DatagramPacket(buffer, buffer.length);
80
odbcServer = new ODBCServer("NTOP");
85
String statement = new String(buffer, 0, pkt.getLength());
87
System.out.println("["+pkt.getLength()+"] '"+statement+"'");
89
odbcServer.executeStatement(statement);
91
pkt.setLength(bufLength);
92
} catch (Exception e) {
99
System.out.println("Done.");