You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
203 lines
5.9 KiB
203 lines
5.9 KiB
package de.superx.dbadmin; |
|
|
|
/** |
|
* Insert the type's description here. Creation date: (08.01.2002 16:15:26) |
|
* |
|
* @author: |
|
*/ |
|
import java.sql.Connection; |
|
import java.sql.ResultSet; |
|
import java.sql.Statement; |
|
import java.util.Enumeration; |
|
import java.util.Vector; |
|
|
|
import javax.swing.JOptionPane; |
|
|
|
class DBAccess { |
|
static Connection myConnection; |
|
static Vector userliste, gruppenliste, maskenliste = null; |
|
static SxSQL sxsql;; |
|
|
|
public static void init(String url, String logToKonsole, String user, |
|
String passwd) throws Exception { |
|
|
|
sxsql = new SxSQL(url, logToKonsole, user, passwd); |
|
|
|
} |
|
|
|
public static String getString(ResultSet rs1, String feldname) { |
|
Object test; |
|
String rückgabe = null; |
|
try { |
|
|
|
test = rs1.getObject(feldname); |
|
if (test != null) |
|
rückgabe = test.toString(); |
|
else |
|
rückgabe = new String(""); |
|
} catch (Exception e) { |
|
} |
|
return rückgabe; |
|
} |
|
|
|
public static String getStringOrNull(String was) { |
|
String back; |
|
if (was.equals("")) |
|
back = null; |
|
else |
|
back = "'" + was.trim() + "'"; |
|
return back; |
|
} |
|
|
|
public static String getIntegerOrNull(String was) { |
|
String back; |
|
if (was.equals("")) |
|
back = null; |
|
else |
|
back = was.trim(); |
|
|
|
return back; |
|
} |
|
|
|
public static Integer getInteger(ResultSet rs1, String feldname) { |
|
Object test; |
|
Integer rückgabe = null; |
|
try { |
|
|
|
test = rs1.getObject(feldname); |
|
if ((test != null) && (test instanceof Integer)) |
|
rückgabe = (Integer) test; |
|
} catch (Exception e) { |
|
} |
|
return rückgabe; |
|
} |
|
|
|
public static Vector getMaskenListe() { |
|
Vector liste = new Vector(); |
|
Vector row; |
|
Integer id; |
|
String name; |
|
try { |
|
|
|
String query = "select tid, name, erlaeuterung, select_stmt, cleanup_stmt,xil_proplist from maskeninfo order by 2"; |
|
liste = executeQuery(query); |
|
} catch (Exception e) { |
|
JOptionPane.showMessageDialog(null, |
|
"Fehler beim Lesen aus der Datenbank: " + e.toString(), |
|
"SuperX DB Admin", JOptionPane.WARNING_MESSAGE); |
|
e.printStackTrace(); |
|
} |
|
return liste; |
|
|
|
} |
|
|
|
public static Vector getUserListe() { |
|
if (userliste == null) |
|
userListeNeuEinlesen(); |
|
return userliste; |
|
} |
|
|
|
static void userListeNeuEinlesen() { |
|
try { |
|
userliste = new Vector(); |
|
Vector row; |
|
Integer id; |
|
String benutzer, email, name, max_versuch, akt_versuch, info; |
|
Object wert; |
|
|
|
String query = "select tid, benutzer,name,email,info,max_versuch,akt_versuch,passwd_sha from userinfo order by benutzer"; |
|
userliste = executeQuery(query); |
|
for (Enumeration en = userliste.elements(); en.hasMoreElements();) { |
|
row = (Vector) en.nextElement(); |
|
for (Enumeration en2 = row.elements(); en2.hasMoreElements();) { |
|
wert = en2.nextElement(); |
|
if (wert == null) |
|
wert = new String(""); |
|
} |
|
} |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
JOptionPane.showMessageDialog(null, "Fehler bei Datenbankzugriff: " |
|
+ e.toString(), "DBAccess", 1); |
|
} |
|
|
|
} |
|
|
|
public static Vector NutzerListeEinlesen_Alt() { |
|
Vector liste = new Vector(); |
|
Vector row; |
|
Integer id; |
|
String benutzer; |
|
try { |
|
|
|
String query = "select tid, benutzer from userinfo order by benutzer"; |
|
Statement statement = myConnection.createStatement(); |
|
ResultSet rs1 = statement.executeQuery(query); |
|
while (rs1.next()) { |
|
id = (Integer) rs1.getObject("tid"); |
|
benutzer = rs1.getObject("benutzer").toString(); |
|
row = new Vector(); |
|
row.add(id); |
|
row.add(benutzer.trim()); |
|
liste.add(row); |
|
|
|
} |
|
rs1.close(); |
|
statement.close(); |
|
|
|
} catch (Exception e) { |
|
JOptionPane.showMessageDialog(null, |
|
"Fehler beim Lesen aus der Datenbank: " + e.toString(), |
|
"SuperX DB Admin", JOptionPane.WARNING_MESSAGE); |
|
e.printStackTrace(); |
|
} |
|
return liste; |
|
} |
|
|
|
public static Vector GruppenListeEinlesen() { |
|
Vector liste = new Vector(); |
|
try { |
|
String query = "select tid, name from groupinfo order by 2"; |
|
liste = executeQuery(query); |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
JOptionPane.showMessageDialog(null, "Fehler bei Datenbankzugriff: " |
|
+ e.toString(), "DBAccess", 1); |
|
} |
|
|
|
return liste; |
|
} |
|
|
|
public static Vector executeQuery(String query) throws Exception { |
|
//ein Vector im Vector wird geliefert |
|
Vector erg = null; |
|
|
|
sxsql.executeQuery(query); |
|
|
|
erg = sxsql.getResultVector(); |
|
return erg; |
|
} |
|
|
|
public static Object executeQuerySingleValue(String query) throws Exception { |
|
Object rück = null; |
|
|
|
Vector erg = executeQuery(query); |
|
//ein Vector im Vector wird geliefert |
|
Vector help = (Vector) erg.get(0); |
|
rück = help.get(0); |
|
|
|
return rück; |
|
} |
|
|
|
public static void executeUpdate(String upd) throws Exception { |
|
|
|
sxsql.execute(upd); |
|
|
|
} |
|
|
|
public static void executeUpdateAll(String upd) throws Exception { |
|
|
|
sxsql.executeAll(upd); |
|
|
|
} |
|
} |