2013年12月17日星期二

Great God seeking guidance on the line , talk about ideas. I do a visual journal management system

I was doing a journal management system, a simple simulation , not really journal management system. I used interface basically done, jump between them almost do it. Sent this one to connect to the database . I use the Access database. I created a database , which also kept a few books . ( 1 ) For example, I want to do : I opened the journal register interface , fill in the property bar book information , click OK, and then you can add this information to the book I created database. ( 2 ) how the information inside the database is also used java interface display, instead of displaying the compiler display bar . That I do not know how to modify the database via the user interface . If when we explain ideas, best detail, such as what to use . Thank you ! ! !
------ Solution ---------------------------------------- controls ----
listening interface window , write control event listener response in the background , and then do the database operations in the listener method, using the java jdbc connection to the database .
------ For reference only -------------------------------------- -
can be a little detail? Like I said, do not generalize too concise ah
------ For reference only ------------------------- --------------
If you want to design for the B / S architecture , the proposed framework for the use of java ssh , you can read the database using hibernate ; If the detailed design for the C / S structure , so as I told you that the top do, use the java swt or awt do interface, and then listen for the event interface , read the database using jdbc listener event code :
		Button
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
//使用jdbc读取数据库的操作
}
});

jdbc If you are not familiar with , you check the Internet , java jdbc.
------ For reference only -------------------------------------- -
simple operation, refer to specific queries like check online : http://blog.csdn.net/baohuan_love/article/details/16968093
------ For reference only -------------------------------------- -

This is my journal to register interface. I want to do is to fill in a journal after information inside these boxes , click OK, and then I've created automatically populated into the database. I now only need to write the journal information in a main function, and then stored in the database .
Below are only able to achieve CRUD code ( I do not have any relationship with the visual interface , and I just built a relationship database can operate databases ) , how can the following code and visual interface linked together ? ?

------ For reference only ---------------------------------- -----

In order to facilitate your viewing , here is the code
import java.sql *.;
import java.util *.;
class datacollection
{
public static void main (String [] args)
{
ModifyTable modify = new ModifyTable ();
modify.setDatasourceName ("starr");
modify.setSQL ("UPDATE employee SET zuozhe = ' Peijiu Ming ' WHERE shuming = ' Signals and Systems ' ' ) ;
String backMess = modify.modifyRecord ();
System.out.println (backMess);
modify.setSQL ("DELETE FROM employee WHERE cbanshe = ' Tsinghua University Press ' " ) ;
backMess = modify.modifyRecord ();
System.out.println (backMess);
modify.setSQL ("INSERT INTO employee VALUES (' Zhang Sining ', ' assembly language ', ' Tsinghua University Press ', '3 ' , '1999 / 4 / 5' ) " ) ;
backMess = modify.modifyRecord ();
System.out.println (backMess);
modify.setSQL ("INSERT INTO employee VALUES (' photos ', ' compile ', ' Tsinghua University ', '5 ', '1999 / 4 / 15' ) " ) ;
backMess = modify.modifyRecord ();
System.out.println (backMess);


}

}
class ModifyTable
{
String datasourceName = "";
String SQL, message = "";
public ModifyTable ()
{
try {
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e)
{
System.out.println (e.toString ());
}

}
public void setSQL (String SQL)
{
this.SQL = SQL;

}
public void setDatasourceName (String s)
{
datasourceName = s.trim ();
}
public String modifyRecord ()
{
Connection con = null;
Statement sql = null;
try {
String uri = "jdbc: odbc:" + datasourceName;
/ / String id = "";
/ / String password = "";
con = DriverManager.getConnection (uri);
sql = con.createStatement ();
sql.execute (SQL);
message = " Operation Success" ;
con.close ();
}
catch (SQLException e)
{
message = e.toString ();
}
return message;
}

}
------ For reference only --------------------------------- ------
monitor button click event, and then get the text content of text in the event function, can be stored in the database , these are swt -based applications , refer to this article http://blog.sina.com.cn/s/blog_4150f50c0100f4si.html
------ For reference only -------------------------------------- -
ah ! Thank you very much , I find the reference , basically the

没有评论:

发表评论