Hey Leute, bin gerade dabei ein SQl Insert Statement zu machen, doch Irgendwas ach ich falsch. Muss ich die Serveradresse umformulieren?
Java:
package test;
import java.sql.BatchUpdateException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import com.mysql.jdbc.PreparedStatement;
public class test1 {
public String scan_result= "haus";
public String price="maus";
public static String url= "jdbc:mysql://sql4.freesqldatabase.com:3306";
public static String user= "******";
public static String pw="******";
public static String scan_rs;
public static String price_rs;
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// Bl�d: Treiber konnte nicht geladen werden.
e.printStackTrace();
}
try {
con = DriverManager.getConnection(url, user, pw);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
// create a Statement from the connection
// Statement statement = con.createStatement();
// insert the data
//statement.executeUpdate("INSERT INTO barcode VALUES (13846, 12,23)");
//("INSERT INTO barcode VALUES (" +"'"+ scan_rs + "'" + ", " + "'" + price_rs + "'" + ")");
PreparedStatement stmt = (PreparedStatement) con.prepareStatement("INSERT INTO table_name(email, pass) VALUES (?, ?)");
stmt.setString(1, scan_rs);
stmt.setString(2, price_rs);
stmt.executeUpdate();
} catch (SQLException e) { System.out.println("fehler2");}
try
{
con.close();
}
catch(SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Anhänge
Zuletzt bearbeitet von einem Moderator: