// AQUI VOYA OBTENER EL SERVDUIOR QUEMADO EN UN ARCHIVO DE TEXTO public void conectarBaseDeDatos2() { try { final String CONTROLADOR = "org.postgresql.Driver"; Class.forName(CONTROLADOR); // System.getProperty( "user.dir" )+"/CarpetaBD/NombredelaBasedeDatos.mdb"; conexion = DriverManager.getConnection(url2, user, pass); sentencia = conexion.createStatement(); /*JOptionPane.showMessageDialog(null, "si conecta");*/ } catch (ClassNotFoundException ex1) { // ex1.printStackTrace(); javax.swing.JOptionPane.showMessageDialog(null, "Error Carga Driver." + ex1.getMessage()); System.exit(1); } catch (SQLException ex) { // ex.printStackTrace(); javax.swing.JOptionPane.showMessageDialog( null, "Error Creacion Statement." + ex.getMessage() + " / " + url2 + " / " + user + " / " + pass); System.exit(1); } }
@Override public void callInsert(String statementString) throws SQLException { /* String sqlString = statementString; CallableStatement statement = sqlConn.prepareCall(sqlString); statement.execute(); int iStatus = statement.getInt(1); sqlConn.commit();*/ Statement statement = sqlConn.createStatement(); // statement.executeU(statementString); Statement s = null; try { s = sqlConn.createStatement(); } catch (SQLException se) { System.out.println( "We got an exception while creating a statement:" + "that probably means we're no longer connected."); se.printStackTrace(); System.exit(1); } int m = 0; try { m = s.executeUpdate(statementString); } catch (SQLException se) { System.out.println( "We got an exception while executing our query:" + "that probably means our SQL is invalid"); se.printStackTrace(); System.exit(1); } System.out.println("Successfully modified " + m + " rows.\n"); }
public void conectarBaseDeDatos() { try { final String CONTROLADOR = "org.postgresql.Driver"; Class.forName(CONTROLADOR); // System.getProperty( "user.dir" )+"/CarpetaBD/NombredelaBasedeDatos.mdb"; conexion = DriverManager.getConnection( "jdbc:postgresql://" + main.ipSeleccionada + "/" + objUtils.nameBD, user, pass); // conexion = DriverManager.getConnection("jdbc:postgresql://127.0.0.1/goliak_jg", "postgres", // "majcp071102kaiser"); sentencia = conexion.createStatement(); /*JOptionPane.showMessageDialog(null, "si conecta");*/ } catch (ClassNotFoundException ex1) { // ex1.printStackTrace(); javax.swing.JOptionPane.showMessageDialog(null, "Error Carga Driver." + ex1.getMessage()); System.exit(1); } catch (SQLException ex) { // ex.printStackTrace(); javax.swing.JOptionPane.showMessageDialog( null, "Error Creacion Statement." + ex.getMessage() + " / " + url + " / " + user + " / " + pass); System.exit(1); } }
private boolean AidedIn(SaoWorker w) { BatSQL bSQL = new BatSQL(); boolean success = false; String id = w.getUserID(); String q = "select * from aidedin where USERID='" + id + "'"; ResultSet rs = bSQL.query(q); try { boolean more = rs.next(); if (more) { success = true; } } //end of try catch (SQLException ex) { System.out.println("!*******SQLException caught*******!"); while (ex != null) { System.out.println ("SQLState: " + ex.getSQLState ()); System.out.println ("Message: " + ex.getMessage ()); System.out.println ("Vendor: " + ex.getErrorCode ()); ex = ex.getNextException (); System.out.println (""); } System.exit(0); } //end catching SQLExceptions catch (java.lang.Exception ex) { System.out.println("!*******Exception caught*******!"); System.exit(0); } //end catching other Exceptions bSQL.disconnect(); return success; } //end of AidedIn?
protected void init() { try { _con = WebAppConnection.getWebAppConnection().getConnection(); } catch (OptInCustomerException ex) { AppLog.writeAuditLog( "OptIN Driver OptInCustomerException: no connection to dB " + ex.getMessage()); System.out.println( "OptIN Driver OptInCustomerException: no connection to dB " + ex.getMessage()); System.exit(1); } catch (Exception exe) { AppLog.writeAuditLog("OptIN Driver Exception: " + exe.getMessage()); System.out.println("OptIn Driver Exception : " + exe.getMessage()); System.exit(1); } }
// public HashMap<String, String> getProjectNames() { // selline oli ta automaatselt tehes! public ArrayList getProjectNames() { ArrayList projektinimed = new ArrayList(); try { Statement stat = conn.createStatement(); String sql = "SELECT PROJECTNAME FROM PROJECTS;"; ResultSet rs = stat.executeQuery(sql); // Kui stat.executeQuery() toob tagasi tühja tulemuse, siis rs'i kasutada ei saa. // Kui oleks mitu rida andmeid, peaks tsükliga lahendama while (rs.next()) {} while (rs.next()) { projektinimed.add(rs.getString("projectname")); } // Nopin käsitsi andmed ühelt realt välja /*andmed.put("username", rs.getString("username")); andmed.put("password", rs.getString("password")); andmed.put("fullname", rs.getString("fullname")); andmed.put("number", rs.getString("number")); andmed.put("address", rs.getString("address"));*/ rs.close(); stat.close(); return projektinimed; } catch (SQLException e) { e.printStackTrace(); System.exit(0); } return projektinimed; }
public TestaSelect(int num_) { Connection connection = null; Statement statement = null; int numero = num_; try { Class.forName(JDBC_DRIVER); connection = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", ""); System.out.println("Conectado: " + connection); statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery("select * from fatura where numero=" + numero); while (resultSet.next()) { System.out.println("Numero: " + resultSet.getInt("numero")); System.out.println("Nome: " + resultSet.getString("nome")); System.out.println("Valor: " + resultSet.getInt("valor")); System.out.println(); } } catch (ClassNotFoundException classNotFound) { System.out.println("Driver nao foi encontrado"); classNotFound.printStackTrace(); } catch (SQLException sqlException) { System.out.println("Erro na conexao"); sqlException.printStackTrace(); } finally { try { connection.close(); statement.close(); } catch (Exception e) { System.out.println("Erro durante fechamento da conexao"); e.printStackTrace(); System.exit(1); } } }
public static void main(String args[]) throws IOException { MissingValues mv = new MissingValues(); while (true) { System.out.println( "Menu : \t1. Global Constant\t2. AtrributeMean\n\t3. Specific AttributeMean\t4. Most ProbableValue\n\t\t\t0. Exit"); switch (in.nextInt()) { case 1: mv.globalConstant(); break; case 2: mv.attributeMean(); break; case 3: mv.specificAttributeMean(); break; case 4: mv.probableValue(); break; case 0: System.exit(0); default: System.out.println("Invalid Option..!"); } } }
public LoginModel() { connector = SqliteConnection.connector(); if (connector == null) { System.out.println("connection not successful"); System.exit(1); } }
public Boolean insertarEquipo(String name, String form, int h1, int h2, int h3, int h4) throws ClassNotFoundException, SQLException { Connection c = null; Statement stmt = null; Boolean boo = true; try { // for (int d = 2; d < 20; d++) { /// asd(); // } System.out.println(cont); Class.forName("com.mysql.jdbc.Driver"); c = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Equipos", "root", "camilo"); c.setAutoCommit(false); stmt = c.createStatement(); String sql = "INSERT INTO Equipos (Nombre,Formacion,Arquero,Defensor,Mediocampo,Ataque) " + String.format("VALUES ('%s','%s',%2d,%2d,%2d,%2d);", name, form, h1, h2, h3, h4); stmt.executeUpdate(sql); cont++; System.out.println("Equipo insertado "); stmt.close(); c.commit(); c.close(); } catch (Exception e) { System.out.println("Error en insertarEquipo"); System.err.println(e.getClass().getName() + ": " + e.getMessage()); System.exit(0); } return boo; }
/** * fügt einen neuen Kontakt zur Kontaktliste hinzu * * @param besitzer Der Besitzer der Kontaktliste * @param kontakt Der Kontakt, der hinzugefügt werden soll */ public void kontaktZurKontaktListeHinzufuegen(String besitzer, String kontakt) { int kNr = bestimmeBNrBenutzer(kontakt); int bNr = bestimmeBNrBenutzer(besitzer); try { // überprüft, ob der Konktakt noch nicht in der Kontaktliste ist boolean gefunden = false; ResultSet rueckgabewert = null; String query1 = "select count(*) from kontaktliste where besitzer = ? and kontakt = ?"; PreparedStatement anweisung1 = con.prepareStatement(query1); anweisung1.setString(1, besitzer); anweisung1.setString(1, kontakt); rueckgabewert = anweisung1.executeQuery(); // werdet den Rückgabewert aus while (rueckgabewert.next()) { gefunden = rueckgabewert.getBoolean(1); } if (!gefunden) { // fügt den Kontakt zur Kontakliste hinzu String query = "insert into kontaktliste (besitzer, kontakt) values(?, ?);"; PreparedStatement anweisung = con.prepareStatement(query); anweisung.setInt(1, bNr); anweisung.setInt(2, kNr); anweisung.executeUpdate(); } } catch (SQLException e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); System.exit(1); } }
private static void moveVoicemail(String strContact, String strID, String strTempVMTS) { System.out.println(strContact + " " + strID + " " + strTempVMTS); try { File fSrc = new File(strSrcVMDir + "/" + strID + ".amr"); File fDest = new File(strDestVMDir + strContact + "/" + strTempVMTS + ".amr"); InputStream isSrc = new FileInputStream(fSrc); OutputStream osDest = new FileOutputStream(fDest); byte[] buf = new byte[1024]; int len; while ((len = isSrc.read(buf)) > 0) { osDest.write(buf, 0, len); } isSrc.close(); osDest.close(); System.out.println("File copied."); } catch (Exception e) { System.err.println(e.getLocalizedMessage()); System.err.println(); System.err.println(e.getStackTrace()); System.exit(0); } }
public void register(RegPanel reg) { if (this.surname.trim().isEmpty()) { JOptionPane.showMessageDialog(reg, "Surname required", "Error", JOptionPane.ERROR_MESSAGE); } else if (this.names.trim().isEmpty()) { JOptionPane.showMessageDialog(reg, "Names required", "Error", JOptionPane.ERROR_MESSAGE); } else if (this.tmp_ID.trim().isEmpty()) { JOptionPane.showMessageDialog(reg, "ID Number required", "Error", JOptionPane.ERROR_MESSAGE); } else if (this.password1.trim().isEmpty()) { JOptionPane.showMessageDialog(reg, "Password required", "Error", JOptionPane.ERROR_MESSAGE); } else if (this.password2.trim().isEmpty()) { JOptionPane.showMessageDialog( reg, "Confirmation Password required", "Error", JOptionPane.ERROR_MESSAGE); } else if (!this.password1.trim().equals(this.password2)) { JOptionPane.showMessageDialog( reg, "Unmatching Passwords", "Error", JOptionPane.ERROR_MESSAGE); } else { this.password = Connector.hash(this.password1); Connection conn = Connector.createConnection(); PreparedStatement stmt; int agent_id; try { this.ID = Long.parseLong(this.tmp_ID); String sql = "INSERT INTO agents (ID_NO,sname,names,password) VALUES (?,?,?,?)"; stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt.setLong(1, this.ID); stmt.setString(2, this.surname); stmt.setString(3, this.names); stmt.setString(4, this.password); stmt.executeUpdate(); ResultSet res = stmt.getGeneratedKeys(); if (res.next()) { agent_id = res.getInt(1); Agent ag = new Agent(agent_id, conn); new SessionController(ag); reg.setVisible(false); new Start().setVisible(true); } else { System.out.println("Error getting insert id"); System.exit(1); } } catch (SQLException e) { JOptionPane.showMessageDialog(reg, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (NumberFormatException e) { JOptionPane.showMessageDialog( reg, "Please enter the ID Number in correct format", "Error", JOptionPane.ERROR_MESSAGE); } } }
// Generate files for given node // Given Hashtable mapping node_name to Vector of cluster names // <Node>.ini File format: // [ Clusters ] // cluster = <clustername> // ... private void dumpNodeInfo(Hashtable all_nodes, String path) throws IOException { PrintWriter node_file; // Iterate over hashtable of nodes and write <Node>.ini file for each for (Enumeration e = all_nodes.keys(); e.hasMoreElements(); ) { String node_name = (String) (e.nextElement()); try { if (path != null) { node_file = createPrintWriter(path + File.separator + node_name + ".ini"); } else { node_file = createPrintWriter(node_name + ".ini"); } node_file.println("[ Clusters ]"); Vector clusters = (Vector) all_nodes.get(node_name); for (Enumeration c = clusters.elements(); c.hasMoreElements(); ) { String cluster_name = (String) (c.nextElement()); node_file.println("cluster = " + cluster_name); } node_file.close(); } catch (IOException exc) { System.out.println("IOException: " + exc); System.exit(-1); } } }
public static void main(String[] args) { createConnection(); JFrame frm = new JFrame(); Object[] options = {"Admin", "User", "Exit"}; int selection = JOptionPane.showOptionDialog( frm, "Choose run mode:", "Untidaled", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); frm.dispose(); switch (selection) { case 0: // Run as admin. map = new WorldMap(true); break; case 1: // Run as user. map = new WorldMap(false); break; case 2: System.exit(0); break; } }
public static void duration() { connectDb(); String sql = "select min(time), max(time), count(*) from " + tablename + ";"; try { ResultSet rs = query.executeQuery(sql); rs.next(); int numCols = rs.getMetaData().getColumnCount(); String minTime = rs.getString(1); String maxTime = rs.getString(2); String numPackets = rs.getString(3); System.out.println( "Experiment " + tablename + "\n\tfrom: " + minTime + "\n\tto: " + maxTime + "\n\tpackets: " + numPackets); } catch (SQLException e) { System.out.println("SQL Exception: " + e); System.exit(1); } }
/** Method declaration */ public void run() { Channel c = init(); if (c != null) { try { while (true) { String sql = mInput.readUTF(); mServer.trace(mThread + ":" + sql); if (sql == null) { break; } write(mDatabase.execute(sql, c).getBytes()); } } catch (Exception e) { } } try { mSocket.close(); } catch (IOException e) { } if (mDatabase.isShutdown()) { System.out.println("The database is shutdown"); System.exit(0); } }
public EquiposDB() { c = null; stmt = null; try { Class.forName("com.mysql.jdbc.Driver"); c = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Equipos", "root", "camilo"); System.out.println("Conectado a Equipo.db"); stmt = c.createStatement(); String sql = "CREATE TABLE IF NOT EXISTS Equipos" + "(ID INT NOT NULL AUTO_INCREMENT," + " Nombre TEXT NOT NULL, " + " Formacion TEXT," + " Arquero INT, " + " Defensor INT, " + " Mediocampo INT, " + " Ataque INT, " + " PRIMARY KEY(ID))"; stmt.executeUpdate(sql); stmt.close(); c.close(); } catch (ClassNotFoundException | SQLException e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); System.exit(0); } System.out.println("Tabla " + nteam + " creada"); }
static void help() { System.out.println(""); System.out.println("Usage: java RawLogger [options] "); System.out.println(" [options] are:"); System.out.println(" -h, --help Display this message."); System.out.println(" --logging Enable Logging."); System.out.println(" Required options (source). "); System.out.println(" And (url, user, pass, tablename). "); System.out.println(" --display Display Packets."); System.out.println(" Required options (source). "); System.out.println(" --createtable Create a table."); System.out.println( " Required options (url, user, pass, tablename)."); System.out.println(" --droptable Drop a table."); System.out.println( " Required options (url, user, pass, tablename)."); System.out.println(" --cleartable Clear a table."); System.out.println( " Required options (url, user, pass, tablename)."); System.out.println(" --duration Summary of Experiement Duration."); System.out.println( " Required options (url, user, pass, tablename)."); System.out.println(" --reset Reseting EPRB and the attached mote "); System.out.println(" Required options (source). "); System.out.println(" --tablename=<name> Specify sql tablename "); System.out.println(" --url=<ip/dbname> JDBC URL. eg: localhost/rsc."); System.out.println(" --user=<user> User of the database."); System.out.println(" --pass=<password> Password of the database."); System.out.println(" --source=<type> Standard TinyOS Source"); System.out.println(" serial@COM1:platform"); System.out.println(" network@HOSTNAME:PORTNUMBER"); System.out.println(" sf@HOSTNAME:PORTNUMBER"); System.out.println(""); System.exit(-1); }
/** erstellt die nötigen Tabellen in der Datenbank, falls sie noch nicht exisiteren */ private void erstelleTabellen() { try { // erstellt die Benutzer-Tabelle String dbQuery = "CREATE TABLE IF NOT EXISTS benutzer (" + "bNr INTEGER PRIMARY KEY AUTOINCREMENT," + "benutzername VARCHAR(45) NOT NULL," + "statusnachricht text," + "statussymbol VARCHAR(4)," + "status_aktuell_seit INTEGER," + "passwort VARCHAR(50) NOT NULL," + "online TINYINT(1));"; con.createStatement().executeUpdate(dbQuery); // erstellt die Kontaklisten-Tabelle dbQuery = "CREATE TABLE IF NOT EXISTS kontaktliste (" + "kId INTEGER PRIMARY KEY AUTOINCREMENT," + "besitzer INTEGER," + "kontakt INTEGER," + "foreign key (besitzer) references benutzer(bNr)," + "foreign key (kontakt) references benutzer(bNr))"; con.createStatement().executeUpdate(dbQuery); } catch (SQLException e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); System.exit(1); } }
// Write <Cluster>.ini file // Given Hashtable mapping cluster name to Vector of plugin names // <Cluster>.ini File format: // [ Cluster ] // uic = <Agentname> // cloned = false // [ Plugins ] // plugin = <pluginname> // ... // private void dumpClusterInfo(Hashtable all_clusters, String path) throws IOException { // Dump hashtable of clusters for (Enumeration e = all_clusters.keys(); e.hasMoreElements(); ) { String cluster_name = (String) e.nextElement(); PrintWriter cluster_file; try { if (path != null) { cluster_file = createPrintWriter(path + File.separator + cluster_name + ".ini"); } else { cluster_file = createPrintWriter(cluster_name + ".ini"); } cluster_file.println("[ Cluster ]"); cluster_file.println("uic = " + cluster_name); cluster_file.println("cloned = false\n"); cluster_file.println("[ Plugins ]"); Vector plugins = (Vector) (all_clusters.get(cluster_name)); for (Enumeration p = plugins.elements(); p.hasMoreElements(); ) { String plugin = (String) (p.nextElement()); cluster_file.println("plugin = " + plugin); } cluster_file.close(); } catch (IOException exc) { System.out.println("IOException: " + exc); System.exit(-1); } } }
private void LogMasuk() { SysConfig sc = new SysConfig(); String pass = ""; char chrPass[] = txtPass.getPassword(); for (int i = 0; i < chrPass.length; i++) { pass = pass + chrPass[i]; chrPass[i] = '0'; } // KasirCon conn = new KasirCon("jdbc:postgresql://"+sc.getServerLoc()+":5432/"+sc.getDBName(), // txtKasir.getText(), pass, this); iCount++; if (iCount == 3) { System.exit(1); } try { Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); // ResultSet rs = st.executeQuery("select usename,usesysid,usesuper from pg_user where // usename='"+ txtKasir.getText().trim() +"'"); String sQry = "select user_id, pwd, username, coalesce(profile, -1) as profile " + "from m_user " + "where username='******' " + "and pwd=md5('" + pass + "') "; ResultSet rs = st.executeQuery(sQry); // System.out.println(sQry); if (rs.next()) { sName = rs.getString("username").trim(); authority = rs.getInt("profile"); // sKota=lstModel.getElementAt(cmbGudang.getSelectedIndex()).toString(); timer.cancel(); setVisible(false); fMain = new MainForm(); fMain.setConn(con); fMain.setUserProfile(rs.getInt("profile")); fMain.setUserName(sName); fMain.setServerLocation(sc.getServerLoc()); fMain.udfSetUserMenu(); fMain.setVisible(true); } else { JOptionPane.showMessageDialog(this, "Silakan masukkan nama user & passwod dengan benar!"); txtKasir.requestFocus(); txtKasir.setSelectionStart(0); txtKasir.setSelectionEnd(txtKasir.getText().length()); } } catch (SQLException se) { JOptionPane.showMessageDialog(this, se.getMessage()); } }
/** * Laad de driver voor hsqldb. Indien de driver niet gevonden wordt, wordt het systeem afgesloten. */ private void laadDriver() { try { Class.forName(driverName); } catch (ClassNotFoundException e) { System.out.println("Driver niet gevonden"); System.exit(1); } }
public void close_resultset(ResultSet rs) { try { rs.close(); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); System.exit(0); } }
private void jMenuItem4ActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem4ActionPerformed if (JOptionPane.showConfirmDialog( rootPane, "Estás seguro de cerrar el Sistema?", "Cerrar Sistema", 1) == 0) { System.exit(0); } } // GEN-LAST:event_jMenuItem4ActionPerformed
public void close_connection(Connection c) { try { c.close(); System.out.println("Connection terminated successfully"); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); System.exit(0); } }
/* * Load the Oracle JDBC driver */ private void loadDriver() { try { // Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); } catch (SQLException ex) { System.out.println("Message: " + ex.getMessage()); System.exit(-1); } }
private void connectToDatabase(String databasePath) { this.connection = null; try { this.connection = DriverManager.getConnection("jdbc:sqlite:" + databasePath); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); System.exit(0); } this.parser = new JSONParser(); }
/** loading the JDBC driver */ private void loadJdbcDriver() { try { Class.forName(driver); } catch (ClassNotFoundException e) { e.printStackTrace(); System.exit(1); } System.out.println("driver loaded"); }
private void btnCancelarActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnCancelarActionPerformed // TODO add your handling code here: int i = JOptionPane.showConfirmDialog( this, "Desea salir?", "Confirmar salida", JOptionPane.YES_NO_OPTION); if (i == 0) { System.exit(0); } } // GEN-LAST:event_btnCancelarActionPerformed