好吧我想用derby数据库制作一个可移植的jar文件。我的表只是为了阅读。所以我只在上面搜索我的代码。我想要的是向我解释如何将德比数据库放在哪里我应该将它粘贴到我的文件上,以及在运行它的任何设备中读取的正确路径是什么... 当我创建jar文件只有代码而不是dabase ...
这是我的连接和搜索查询的代码
package ARMY;
import com.sun.glass.events.KeyEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
import org.apache.derby.jdbc.EmbeddedDriver;
/**
*
* @author Ccompany
*/
public class Menu extends javax.swing.JFrame {
/**
* Creates new form Menu
*/
public Menu() {
initComponents();
findUsers();
}
String driver ="org.apache.derby.jdbc.EmbeddedDriver";
String url ="jdbc:derby://localhost:1527/ABYP;create=true";
String user ="db";
String pass ="sql!123";
public Connection getConnection()
{
Connection con;
try {
Class.forName(driver);
con=DriverManager.getConnection(url, user, pass);
return con;
}catch (Exception e){
e.printStackTrace();
return null;
}
}
public ArrayList <Tablearray>ListUsers(String ValToSearch){
ArrayList <Tablearray> usersList = new ArrayList <Tablearray>();
Statement st;
ResultSet rs;
try {
Connection con = getConnection();
st = con.createStatement();
String searchQuery = "SELECT * FROM ABYP WHERE Id_Search||Tyl||Apothkh||Parathrhseis||Ti LIKE '%"+ValToSearch+"%'";
// String searchQuery = "SELECT * FROM ABYP WHERE CONCAT ('Id_Search) LIKE '%||"+ValToSearch+"||%'";
//String searchQuery = "SELECT *FROM ABYP where ID_SEARCH =? ";
rs = st.executeQuery(searchQuery);
Tablearray tablearray;
while (rs.next()){
tablearray = new Tablearray (
rs.getString("Id_Search"),
rs.getString("Tyl"),
rs.getString("Apothkh"),
rs.getString("Parathrhseis"),
rs.getString("Ti")
);
usersList.add(tablearray);
}
}catch(Exception ex){
System.out.println(ex.getMessage());
}
return usersList;
}
public void findUsers()
{
ArrayList<Tablearray> users = ListUsers(jText_Searchh.getText());
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(new Object[]{"Id_Search","Tyl","Apothkh","Parathrhseis","Ti"});
Object[] row = new Object[5];
for(int i = 0; i < users.size(); i++)
{
row[0] = users.get(i).getid_Search();
row[1] = users.get(i).gettyl();
row[2] = users.get(i).getapothkh();
row[3] = users.get(i).getparathrhseis();
row[4] = users.get(i).getti();
model.addRow(row);
}
jTable_Userss.setModel(model);
}
我认为我的derby数据是在我的derby netbeans文件夹中找到它应该复制粘贴日志文件与seg0文件在某处? finnaly我插入来自netbeans derby数据库的所有行而不是使用create table方法是否可以使其可移植?
答案 0 :(得分:0)
好的,我找到了一些测试后的答案,对于那些想要让它工作的人我们清理并在将连接URL更改为此后构建文件夹
String driver ="org.apache.derby.jdbc.EmbeddedDriver";
String url ="jdbc:derby:.\\ABYP";
String user ="db";
String pass ="sql!123";
然后我们从netbeans项目dist文件中复制下面的文件(lib,jar,readme),然后我们将包含log seg的dabase文件夹ex ABYP以及derby的其他内容粘贴到我们usb中的文件上netbeans目的地。然后我们将它粘贴在我们的usb文件夹中,它工作得很好!!!