我尝试使用 java 程序连接到嵌入式 derby db。它在 Windows 10 上运行良好,当我从 ubuntu 中的 eclipse 运行它时,但是当我在终端中运行 jar 时,它会抛出:
"java.sql.SQL.SintaxErrorException:Table/View 'REGISTRATION' does not exist."
我需要在 ubuntu 中设置一些东西才能使其工作吗?
....................................................
public class JDBC {
................................................
static Connection conn = null;
............................................
try{
Driver derbyEmbeddedDriver = new EmbeddedDriver();
DriverManager.registerDriver(derbyEmbeddedDriver);
String dbURL = "jdbc:derby:MyDB;create=true";
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(dbURL);
System.out.println("Connected database successfully...");
}catch(SQLException se){
se.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}
................................................................
JButton btnLogin = new JButton("Login");
btnLogin.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
String query="select * from REGISTRATION where NUME=? and PRENUME=?";
PreparedStatement pst=conn.prepareStatement(query);
pst.setString(1, textField.getText());
pst.setString(2, passwordField.getText());
ResultSet rs=pst.executeQuery();
int count=0;
while(rs.next()){
count=count+1;
}
if (count == 1 )
{
JOptionPane.showMessageDialog(null, "Conectat");
}
else
{
JOptionPane.showMessageDialog(null, "Nume sau parola gresite!");
}
rs.close();
pst.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
});
btnLogin.setBounds(25, 182, 117, 25);
frame.getContentPane().add(btnLogin);
.................................................................