我尝试使用java程序连接到嵌入式derby数据库。它在Windows 10上运行良好,当我在ubuntu中从eclipse运行时,但是当我在终端中运行jar时它会抛出:
“java.sql.SQL.SintaxErrorException:表/视图'REGISTRATION'没有 存在。“
我是否需要在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);
.................................................................
答案 0 :(得分:0)
对不起伙计们。我在我的机器上重新安装了ubuntu并且它可以工作。我的操作系统有点麻烦。