M
Mart
Gast
deHallo,
In dieser Frage geht es nicht um einen Fehler sondern ich habe noch nicht das umfangreiche Wissen wie man Sachen macht bzw wie man Sachen aus gewissen Gründen NICHT machen sollte ich aber trotzdem mach weil ich das wissen dazu nicht habe, könnte ich Hinweise und meinungen zu dem Code bekommen den ich habe damit man den verbessern kann.
Der Code funktioniert...wahrscheinlich mehr schlecht als recht... xD
Der Code ist ein "Admin" Tool ...es wird und darf nur von meinen Leuten benutzt werden es wird nicht an den Client gegeben
Die java database Connector zeigt auf eine SQLite Datei die die Datenbank ist
Im Moment sind das alles Fixe Pfade auf meinem Laptop das wird dann später geändert je nachdem wo es dann benutzt wird
[CODE lang="java" title="SQLCode"]package sqltest;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class DataBaseController{
private static Connection connection = null;
private static Statement statement;
private static final String csvDelimiter = ",";
private String CreatureCardCsvPath = "/home/legacy/Dokumente/CardDatabaseCsv.csv";
private static String currentPath ="",line = "";
private static DataBaseController db = new DataBaseController();
public static void main(String[] args) throws Exception{
try{
connection = DriverManager.getConnection("jdbc:sqlite:/home/legacy/Bilder/CardDatabse.db");
statement = connection.createStatement();
statement.setQueryTimeout(30);
db.startInsertionOfCsv(db.CreatureCardCsvPath);
}
catch(SQLException e){
System.err.println(e.getMessage());
}
finally {
closesConnection();
}
}
public static void closesConnection(){
try{
if(connection != null) connection.close();
}
catch(SQLException e){
System.err.println(e.getMessage());
}
}
public void startInsertionOfCsv(String path) throws IOException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
currentPath = path;
DataBaseController k=new DataBaseController();
String text = "creatureInsertion";
Class<? extends DataBaseController> c = getClass();
Method m=c.getDeclaredMethod(text);
m.invoke(k);
}
public static void creatureInsertion() throws Exception {
BufferedReader br = null;
br = new BufferedReader(new FileReader(currentPath));
line = "";
while ((line = br.readLine()) != null) {
String[] cardValueLine = line.split(csvDelimiter);
PreparedStatement ps = connection.prepareStatement(
"INSERT INTO CreatureCards ( Name,Image ,Effect, HealthPoints , Strength , Level, Artist ) VALUES (?,?,?,?,?,?,?) ");
ps.setString(1, cardValueLine[0]);
File file = new File("/home/legacy/CardImages/"+cardValueLine[1]+".png");
FileInputStream fis = new FileInputStream(file);
ps.setBinaryStream(2, fis,(int)file.length());
ps.setString(3, cardValueLine[2].replace("\\n",System.lineSeparator()));
ps.setInt(4,Integer.parseInt(cardValueLine[3]));
ps.setInt(5,Integer.parseInt(cardValueLine[4]));
ps.setInt(6,Integer.parseInt(cardValueLine[5]));
ps.setString(7,cardValueLine[6]);
ps.executeUpdate();
ps.close();
}
br.close();
}
}[/CODE]
In dieser Frage geht es nicht um einen Fehler sondern ich habe noch nicht das umfangreiche Wissen wie man Sachen macht bzw wie man Sachen aus gewissen Gründen NICHT machen sollte ich aber trotzdem mach weil ich das wissen dazu nicht habe, könnte ich Hinweise und meinungen zu dem Code bekommen den ich habe damit man den verbessern kann.
Der Code funktioniert...wahrscheinlich mehr schlecht als recht... xD
Der Code ist ein "Admin" Tool ...es wird und darf nur von meinen Leuten benutzt werden es wird nicht an den Client gegeben
Die java database Connector zeigt auf eine SQLite Datei die die Datenbank ist
Im Moment sind das alles Fixe Pfade auf meinem Laptop das wird dann später geändert je nachdem wo es dann benutzt wird
[CODE lang="java" title="SQLCode"]package sqltest;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class DataBaseController{
private static Connection connection = null;
private static Statement statement;
private static final String csvDelimiter = ",";
private String CreatureCardCsvPath = "/home/legacy/Dokumente/CardDatabaseCsv.csv";
private static String currentPath ="",line = "";
private static DataBaseController db = new DataBaseController();
public static void main(String[] args) throws Exception{
try{
connection = DriverManager.getConnection("jdbc:sqlite:/home/legacy/Bilder/CardDatabse.db");
statement = connection.createStatement();
statement.setQueryTimeout(30);
db.startInsertionOfCsv(db.CreatureCardCsvPath);
}
catch(SQLException e){
System.err.println(e.getMessage());
}
finally {
closesConnection();
}
}
public static void closesConnection(){
try{
if(connection != null) connection.close();
}
catch(SQLException e){
System.err.println(e.getMessage());
}
}
public void startInsertionOfCsv(String path) throws IOException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
currentPath = path;
DataBaseController k=new DataBaseController();
String text = "creatureInsertion";
Class<? extends DataBaseController> c = getClass();
Method m=c.getDeclaredMethod(text);
m.invoke(k);
}
public static void creatureInsertion() throws Exception {
BufferedReader br = null;
br = new BufferedReader(new FileReader(currentPath));
line = "";
while ((line = br.readLine()) != null) {
String[] cardValueLine = line.split(csvDelimiter);
PreparedStatement ps = connection.prepareStatement(
"INSERT INTO CreatureCards ( Name,Image ,Effect, HealthPoints , Strength , Level, Artist ) VALUES (?,?,?,?,?,?,?) ");
ps.setString(1, cardValueLine[0]);
File file = new File("/home/legacy/CardImages/"+cardValueLine[1]+".png");
FileInputStream fis = new FileInputStream(file);
ps.setBinaryStream(2, fis,(int)file.length());
ps.setString(3, cardValueLine[2].replace("\\n",System.lineSeparator()));
ps.setInt(4,Integer.parseInt(cardValueLine[3]));
ps.setInt(5,Integer.parseInt(cardValueLine[4]));
ps.setInt(6,Integer.parseInt(cardValueLine[5]));
ps.setString(7,cardValueLine[6]);
ps.executeUpdate();
ps.close();
}
br.close();
}
}[/CODE]