未找到derby数据库嵌入式模式的Java Desktop应用程序错误

时间:2015-03-18 08:15:26

标签: java sql database derby

我有一个问题。我想创建一个java应用程序,我将部署到具有derby嵌入式数据库的其他PC。当我在netbeans中运行应用程序时它工作得很好!!!!!我连接到db;我可以毫无问题地插入数据。然而,在通过Jar2exe生成exe之后,它向我显示了一个错误,使得架构不存在,正如您在屏幕截图中看到的那样!!!!!我是德比新手,这是我的第一个申请。

package cd.espoir.GestionCarburantVodacom;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Espoir M
 */
public class ConnectToDb{
//creationBDDerby.sql
   

  
    public static Connection Connect() {
//        String dbURL = "jdbc:derby:Vodacom";
//        Properties properties = new Properties();
//        properties.put("create", "true");
//        properties.put("user", "vodacom");
//        properties.put("password", "vodacom");
        Connection con = null;
        String dbURL = "jdbc:derby://localhost:1527/sample;create=true;user=app;password=app";
        try {

   // Configures and loads Database
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
            con = DriverManager.getConnection("jdbc:derby:VODACOM;create=true", "vodacom" ,"vodacom");


            System.out.println("chargement recu");

        } catch (SQLException | ClassNotFoundException | InstantiationException| IllegalAccessException ex) {
            Logger.getLogger(ConnectToDb.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println(ex);
        }
        return con;
    }
//    public static void main(String[] args) throws SQLException, FileNotFoundException {
//         InputStream sqlRequest = new FileInputStream(new File("creationBDDerby.sql"));
//        Connection Connect = Connect();
//        Statement st = Connect.createStatement();
//   
//               importSQL(Connect, sqlRequest);
//        System.out.println("executio parfaitemen ok");
//    }
//    public static void importSQL(Connection conn, InputStream in) throws SQLException
//{ /** la methode execute une requete sql depuis iun fichier sql en pararamtre **/
//	Scanner s = new Scanner(in);
//	s.useDelimiter("(;(\r)?\n)|(--\n)");
//	Statement st = null;
//	try
//	{
//		st = conn.createStatement();
//		while (s.hasNext())
//		{
//			String line = s.next();
//			if (line.startsWith("/*!") && line.endsWith("*/"))
//			{
//				int i = line.indexOf(' ');
//				line = line.substring(i + 1, line.length() - " */".length());
//			}
//
//			if (line.trim().length() > 0)
//			{
//				st.execute(line);
//			}
//		}
//	}
//	finally
//	{
//		if (st != null) st.close();
//	}
//}
 public boolean Verifier() {
        if (jTextField_Nom.getText().isEmpty() || jTextField_Nom.getText() == "") {
         
            jTextPane1_succesfull.setText("Veuillez saisir le nom");
               jTextPane1_succesfull.setForeground(Color.red);
            return true;
        } else {
            Connection cnx = ConnectToDb.Connect();
            try {

                String request = "SELECT Nom FROM Utilisateur where Nom='" + jTextField_Nom.getText() + "'";
                PreparedStatement ps = cnx.prepareStatement(request);
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                 
                    jTextPane1_succesfull.setText("cet Agent  est deja enregistre");
                       jTextPane1_succesfull.setForeground(Color.red);
                    return true;
                } else {
                    return false;
                }

            } catch (SQLException ex) {
                System.out.println(ex);

            }
        }

        return false;

    }
// the comment code was use to create tables in database 

    enter code here

    public void AddUser() {
        Verifier();
        if (!Verifier()) {
            try {
                Connection cnx = ConnectToDb.Connect();
                PreparedStatement ps = cnx.prepareStatement("INSERT INTO Utilisateur (Nom, Service, Fonction) \n"
                        + "	VALUES (?, ?, ?)");
                ps.setString(1, jTextField_Nom.getText());
                ps.setString(2, (String) jComboBox_Service.getSelectedItem());
                ps.setString(3, (String) jComboBox_Fonction.getSelectedItem());
                ps.executeUpdate();
                cnx.close();
                ps.close();
               
                jTextPane1_succesfull.setText("Agent  ajouter avec suceess");
                     jTextPane1_succesfull.setForeground(Color.green);
                jButton_Valider.setEnabled(false);
                jTextField_Nom.setText(" ");
            } catch (SQLException ex) {
                System.out.println(ex);

            }
        }
    }
 }

0 个答案:

没有答案