Hallo Leute,
ich hab mal eine Frage zum erstellen einer MySQL Datenbanktabelle per Java Programm.
In welche Syntax muss dieses erfolgen, eine Verbindung zum Datenbank System steht.
Habe diese Auch mit select Befehlen getestet.
Vielen Dank im vorraus.
ich hab mal eine Frage zum erstellen einer MySQL Datenbanktabelle per Java Programm.
In welche Syntax muss dieses erfolgen, eine Verbindung zum Datenbank System steht.
Habe diese Auch mit select Befehlen getestet.
Vielen Dank im vorraus.
Code:
import java.sql.*;
public class CreatTable
{
static Connection con;
static Statement statement;
static ResultSet result;
public static void main (String args[]){
new CreatTable();
}
public void DatenbankAbfrage()
{
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}
catch (Exception e)
{
System.out.println("Treiber Fehler");
}
/** --------------------------------------------------------------------------------------- **/
/** *************************************************************************************** **/
/** --------------------------------------------------------------------------------------- **/
try
{
con = DriverManager.getConnection("jdbc:mysql://localhost/mkb","root", "");
}
catch (SQLException e)
{
System.out.println("Connection Fehler: " +e.getMessage());
}
/** --------------------------------------------------------------------------------------- **/
/** *************************************************************************************** **/
/** --------------------------------------------------------------------------------------- **/
try
{
statement = con.createStatement();
}
catch (SQLException e)
{
System.out.println("Error creating statement: " + e.getMessage());
}
/** --------------------------------------------------------------------------------------- **/
/** *************************************************************************************** **/
/** --------------------------------------------------------------------------------------- **/
try
{
PreparedStatement pstmt =
con.prepareStatement[COLOR="Red"]("CREATE TABLE mkb, Wohnung1 (Wname TEXT NOT NULL) ENGINE = MYISAM");[/COLOR]
result = pstmt.executeQuery();
}
catch (SQLException e)
{
System.out.println("Error prepared select-statement: " + e.getMessage());
}
}
}
Zuletzt bearbeitet: