public class main extends javax.swing.JFrame {
String wersja = "0.5";
String sciezka = "/Game/";
Connection pol = null;
PreparedStatement ptmt = null;
ResultSet rs = null;
int is = 1;
int i = 0; //czas
public main() {
initComponents();
try {
runapp();
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
} catch (FileNotFoundException ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
}
check();
}
public void connect() {
String[] tablica = new String[5];
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("db.txt"), "UTF8"));
for (int i = 0; i < 5; i++) {
tablica[i] = reader.readLine();
}
reader.close();
} catch (Exception ekk) {
}
;
String url = tablica[0];
String port = tablica[1];
String baza = tablica[2];
String logindb = tablica[3];
String haslodb = tablica[4];
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception exe) {
System.out.println("Exception: " + exe.getMessage());
}
try {
pol = (Connection) DriverManager.getConnection("jdbc:mysql://" + url + ":" + port + "/" + baza, logindb, haslodb);
} catch (Exception ex) {
System.out.println("Exception: " + ex.getMessage());
ex.printStackTrace();
System.out.println("Nie połączono z bazą.");
}
}
**void exec() {
Runtime run = Runtime.getRuntime();
try {
Process pp = run.exec("c:\\Windows\\notepad");
BufferedReader in = new BufferedReader(new InputStreamReader(pp.getErrorStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
int exitVal = pp.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}**
public void runapp() throws UnsupportedEncodingException, FileNotFoundException, IOException{
connect();
String update = null;
try{
ptmt = (PreparedStatement) pol.prepareStatement("select `uptodate_kp` from admin;");
System.out.println(ptmt); }
catch (SQLException ex) { }
try{
rs = ptmt.executeQuery();
while(rs.next()) {
update=rs.getString("uptodate_kp");
}
rs.close();
pol.close();
System.out.println(update);
System.out.println(wersja);}
catch(Exception ek){}
if(update.equals(wersja)){
** exec();**
String[] tablica = new String[1];
BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream("profil.txt"), "UTF8"));
for (int i=0; i<1; i++){
tablica[i]=reader.readLine();
System.out.println(tablica[i]);}
reader.close();
a_field.setText(tablica[0]);
a = tablica[0];}
else{ download dw = new download();
dw.setVisible(true);
dw.setAlwaysOnTop(true);
}
}
}
Początek kodu, reszty nie ma sensu wstawiać.
Funkcja runapp() jest główną funkcją programu.