package projectData;
import java.sql.*;
/**
*
* @author Carlos
*/
public class projectData {
//Database Globals
Connection con;
Statement stmt;
ResultSet Result;
public static void main(String[] args) {
new projectData();
}
//--------------------------------------------------------------------------------------------
public projectData(){
Connect();
Selectdata();
Displaydata();
}
//-----------------------------------------------------------------------------------------------------
public void Connect(){
try{
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/DB");
Statement stmt = con.createStatement( );
String SQL = "SELECT * FROM COLLEAGUES";
ResultSet Result = stmt.executeQuery( SQL );
}
catch (SQLException err){
System.out.println(err.getMessage());
}
}
//-------------------------------------------------------------------------------------------------------------
public void Selectdata(){
try{
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String SQL = "SELECT * FROM COLLEAGUES";
Result = stmt.executeQuery(SQL);
}
catch(Exception X){}
}
//-----------------------------------------------------------------------------------------------------------------
public void Displaydata(){
try{
Result.next();
String TF_ID = Result.getString("ID");
String TF_FIRSTNAME = Result.getString("FIRSTNAME");
String TF_LASTNAME = Result.getString("LASTNAME");
String TF_TITLE = Result.getString("TITLE");
String TF_DEPARTAMENT = Result.getString("DEPARTAMENT");
String TF_EMAIL = Result.getString("EMAIL");
}
catch(Exception x){}
}
}
好的,这是我试图在两层创建这个JDBC结构的东西,一层是实际代码,我从表中获取所有数据并拥有所有SQL语句。另一层是我展示东西的GUI。
我的问题是,如果可以通过运行方法只在我的GUI中显示信息,或者我必须在我的GUI中建立与数据库的连接。(我没有太多尝试,我只是想知道如果我失去了时间)
请保持温柔我是一个完全的菜鸟,我正在努力学习:)。
谢谢:D。