Advertisement
Guest User

Untitled

a guest
May 10th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package servletsql;
  7. import java.sql.*;
  8. import java.io.*;
  9. import java.lang.*;
  10.  
  11. /**
  12.  *
  13.  * @author Gulsort
  14.  */
  15. public class Main {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) throws Exception {
  21.     Connection conn = getHSQLConnection();
  22.     Statement st = conn.createStatement();
  23.     //st.executeUpdate("create table survey (id int,name varchar(30));");
  24.     st.executeUpdate("DELETE FROM testtabel WHERE DATA1 = 24");
  25.     st.executeUpdate("insert into testtabel (DATA1, DATA2) values (24,'pis i låget')");
  26.     st = conn.createStatement();
  27.     ResultSet rs = st.executeQuery("SELECT * FROM testtabel where id = 1");
  28.  
  29.     ResultSetMetaData rsMetaData = rs.getMetaData();
  30.  
  31.     int numberOfColumns = rsMetaData.getColumnCount();
  32.     System.out.println("Antallet af kolonner er = " + numberOfColumns);
  33.     while (rs.next()) {
  34.     String hvadmonderståridata2 = rs.getNString("DATA2");
  35.     System.out.println(hvadmonderståridata2);
  36.     try {
  37.         Runtime rt=Runtime.getRuntime();
  38.         rt.exec("cmd.exe /C start C:\\xmldump.bat");
  39.         System.out.println("Dump made!");
  40.     }
  41.     catch (Exception u)
  42.     {
  43.         System.out.println("Something went horribly wrong!!!");
  44.     }
  45.     /* Alt muligt forsøgskode - kan faktisk bare slettes xD
  46.     rt.exec("cmd.exe");
  47.     rt.exec("cmd.exe /C start C:\\wamp\\bin\\mysql\\mysql5.1.33\\bin\\mysqldump.exe TEST testtabel -u root -x > C:\\sqludtræk.xml");
  48.     C:\wamp\bin\mysql\mysql5.1.33\bin\mysqldump.exe TEST testtabel -u root -x
  49.     Process p = Runtime.getRuntime().exec("c:\myprogram.exe");
  50.     Process p = Runtime.getRuntime().exec("C:\\wamp\\bin\\mysql\\mysql5.1.33\\bin\\mysqldump.exe TEST testtabel -u root -x > C:\\Documents and Settings\\Gulsort\\My Documents\\NetBeansProjects\\ServletSQL\\sqludtræk.xml");
  51.     String temp = " ";
  52.     FileWriter xmlting = new FileWriter("sqludtræk.xml");
  53.     PrintWriter skriv = new PrintWriter(xmlting);
  54.     skriv.println("" + temp);
  55.     skriv.close();
  56.      */
  57.  
  58.     }
  59.  
  60.     rs.close();
  61.     st.close();
  62.     conn.close();
  63.   }
  64.  
  65.   private static Connection getHSQLConnection() throws Exception {
  66.     Class.forName("com.mysql.jdbc.Driver");
  67.     String url = "jdbc:mysql://localhost/TEST";
  68.     return DriverManager.getConnection(url, "root", "");
  69.   }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement