Devo creare GUI con la JTable ma ho problemi con import sto usando eclipse elios e jre e mysql di easyphp, quali import devo usare?
codice:
package database;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.util.ArrayList;
public class Main {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
getConnection();
createTable();
insertTable();
get();
}
// SELECT
public static ArrayList<String> get()throws Exception{
try{
Connection con = getConnection();
PreparedStatement statement = con.prepareStatement("SELECT first, last FROM tablejava");
ResultSet result = statement.executeQuery();
ArrayList<String> array = new ArrayList<String>();
while(result.next()){
System.out.print(result.getString("first"));
System.out.print(" ");
System.out.println(result.getString("last"));
array.add(result.getString("last"));
}
System.out.println("All record have been selected!");
return array;
}catch(Exception e){System.out.println(e);}
return null;
}
//INSERIMENTO DATI
public static void insertTable() throws Exception{
final String var1 = "Giampiero";
final String var2 = "Pagliara";
try{
Connection con = getConnection();
PreparedStatement posted = con.prepareStatement("INSERT INTO tablejava(first,last)VALUES('"+var1+"','"+var2+"')");
posted.executeUpdate();
}catch(Exception e){System.out.println(e);}
finally{
System.out.println("Insert complete.");
}
}
//CREA TABELLA
public static void createTable() throws Exception{
try{
Connection con = getConnection();
PreparedStatement create = con.prepareStatement("CREATE TABLE IF NOT EXISTS tablejava(id int NOT NULL AUTO_INCREMENT,first varchar(255),last varchar(255),PRIMARY KEY(id))");
create.executeUpdate();
}catch(Exception e){System.out.println(e);}
finally{System.out.println("Function complete.");}
}
//CONNESSIONE
public static Connection getConnection()throws Exception{
try{
String driver ="com.mysql.jdbc.Driver";
String url ="jdbc:mysql://localhost:3306/my_db";
String username = "root";
String password = "";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url,username,password);
System.out.println("Connected");
return conn;
}catch(Exception e){System.out.println(e);}
return null;
}
}