Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1
    abhijit is offline Member
    Join Date
    Sep 2009
    Posts
    24
    Rep Power
    0

    Post Executin jar file

    I've developed a appicatiob in java which will detect the bluetooth devices
    and transfer contents to it.
    i created it in netbeans 5.5. when i run the application in ide it works ok..
    but when i double click the jar file or try to run it from command prompt it gives the error "main class not found programm will exit".
    there are two files in my application
    1st file contains 3 classes out of which 1 is public which i;ve set as a main class from netbeans ide.
    and another file contains 1 class.
    please help me urgently..
    i;m totally new to java

    here is my code...


    1st file name:test_final.java
    ---------------------------------------------------------------------

    import de.avetana.javax.obex.*;
    import de.avetana.obexsolo.OBEXConnector;
    import java.awt.*;
    import java.awt.event.*;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import java.io.*;
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.text.ParseException;
    import java.util.Vector;
    import javax.bluetooth.*;
    import javax.swing.*

    public class test_final extends JFrame {
    public static void main(String args[])
    {
    EventQueue.invokeLater(new Runnable() {

    public void run()
    {
    try
    {
    (new test_final()).setVisible(false);
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    }

    });
    }
    private class servicediscovery
    implements DiscoveryListener
    {

    public void deviceDiscovered(RemoteDevice remotedevice, DeviceClass deviceclass)
    {
    }

    public void inquiryCompleted(int j)
    {
    }

    public void servicesDiscovered(int transID, ServiceRecord servRecord[])
    {
    testurl = servRecord[0].getConnectionURL(0, true);
    String newstr[] = testurl.split(":", 2);
    UStr = (new StringBuilder()).append("btgoep:").append(newstr[1]).toString();
    System.out.println((new StringBuilder()).append("FinalUrl: ").append(UStr).toString());
    javax.bluetooth.DataElement serviceNameElement = servRecord[0].getAttributeValue(256);
    System.out.println((new StringBuilder()).append("serviceNameElement: ").append(serviceNameElement).toString());
    javax.bluetooth.DataElement serviceNameElement1 = servRecord[0].getAttributeValue(1);
    System.out.println((new StringBuilder()).append("serviceNameElement1: ").append(serviceNameElement1).toString());
    }

    public void serviceSearchCompleted(int transID, int respCode)
    {
    if(respCode == 1)
    {
    SendPin(SrNo, 0);
    System.out.println("After Send PIN Called...............................");
    if(Send_What_flag.toLowerCase().trim().equals("con tent"))
    {
    //get the file path in string array
    String File_path = WaitForVerificationFlag(SrNo);
    System.out.println("Content path in Test_final");
    send_content(SrNo, 0, File_path);
    System.out.println("SendContent called called End...");
    }
    } else
    {
    SendPin(SrNo, -1);
    System.out.println("Problem in Service discovery...");
    System.out.println("Problem in Service discovery...");
    }
    }

    final test_final this$0;

    public servicediscovery()
    {
    this$0 = test_final.this;

    try
    {
    discoveryAgent.searchServices(attrSet, uuids, (RemoteDevice)rd_vector.elementAt(R_Device_Cnt), this);
    }
    catch(Exception e)
    {
    System.out.println((new StringBuilder()).append("Service Discovery Error: ").append(e.toString()).toString());
    }
    }
    }

    private class devicediscovery
    implements DiscoveryListener
    {

    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod)
    {
    try
    {
    if(cod.getMajorDeviceClass() == 512)
    {
    rd_vector.addElement(btDevice);
    giveConnection connobj = new giveConnection();
    conn = connobj.ConnectionType4Provider();
    System.out.println((new StringBuilder()).append("btName :").append(btDevice.getFriendlyName(true)).append( "BtAddress :").append(btDevice.getBluetoothAddress()).append( BT_Dev_cnt).toString());
    connobj.Enter_Devices(btDevice.getFriendlyName(tru e), btDevice.getBluetoothAddress(), conn, BT_Dev_cnt);
    BT_Dev_cnt++;
    System.out.println((new StringBuilder()).append(btDevice.getFriendlyName(t rue)).append(" : ").append(btDevice.getBluetoothAddress()).append(" BT_Dev_cnt: ").append(BT_Dev_cnt).toString());
    }
    }
    catch(Exception e)
    {
    System.out.println((new StringBuilder()).append("Error: ").append(e.toString()).toString());
    }
    }

    public void inquiryCompleted(int discType)
    {
    String message = null;
    BT_Dev_cnt = 0;
    UUID uuids[] = {
    new UUID(4357L)
    };
    if(discType == 0)
    {
    message = "INQUIRY COMPLETED";
    giveConnection connobj = new giveConnection();
    try
    {
    conn = connobj.ConnectionType4Provider();
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    int n;
    try
    {
    n = connobj.insert_BT_Devices_Flag(conn);
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    SrNo = -1;
    SrNo = WaitForSelectFlag();
    System.out.println((new StringBuilder()).append("SrNo= ").append(SrNo).toString());
    if(SrNo != -1)
    if(SrNo == -2)
    {
    try
    {
    conn = connobj.ConnectionType4Provider();
    connobj.Empty_BT_Table(conn);
    connobj.Empty_BT_Confirmation(conn);
    int n1 = connobj.Enter_info(conn);
    System.out.println((new StringBuilder()).append("n :").append(n1).toString());
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    catch(ParseException ex)
    {
    ex.printStackTrace();
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    devicediscovery dd = new devicediscovery();
    } else
    {
    R_Device_Cnt = SrNo;
    System.out.println("After wait (5-10-2007)......");
    System.out.println((new StringBuilder()).append("Remote Rd: ").append(((RemoteDevice)rd_vector.elementAt(SrNo) ).getBluetoothAddress()).toString());
    System.out.println((new StringBuilder()).append("R_Device_Cnt :").append(R_Device_Cnt).toString());
    servicediscovery dd = new servicediscovery();
    }
    } else
    if(discType == 5)
    message = "INQUIRY TERMINATED";
    else
    if(discType == 7)
    {
    message = "INQUIRY ERROR";
    devicediscovery dd = new devicediscovery();
    }
    System.out.println(message);
    }

    public int WaitForSelectFlag()
    {
    int SrNo = 0;
    int flag = 0;
    try
    {
    giveConnection connobj = new giveConnection();
    conn = connobj.ConnectionType4Provider();
    System.out.println("In WaitForSelectFlag...");
    do
    {
    if(flag != 0)
    break;
    System.out.println((new StringBuilder()).append("In WaitForSelectFlag in while ...flag=").append(flag).toString());
    SrNo = connobj.Check_Select_Dev_Flag(conn);
    System.out.println((new StringBuilder()).append("In WaitForSelectFlag...in if(RS!= null) in while.... SrNo=").append(SrNo).toString());
    if(SrNo != -1)
    flag = 1;
    } while(true);
    }
    catch(Exception ex)
    {
    System.out.println((new StringBuilder()).append("Error in WaitForSelectFlag() Function.............").append(ex.toString()).toSt ring());
    }
    return SrNo;
    }

    public void servicesDiscovered(int j, ServiceRecord aservicerecord[])
    {
    }

    public void serviceSearchCompleted(int j, int k)
    {
    }

    // public void main(String args1[])
    //{
    // }

    final test_final this$0;

    public devicediscovery()
    {
    this$0 = test_final.this;

    rd_vector = new Vector();
    try
    {
    System.out.println("Start Remote Device Discovery");
    discoveryAgent.startInquiry(0x9e8b33, this);
    }
    catch(Exception e)
    {
    System.out.println("Error in Remote Device Discovery");
    repaint(100L);
    }
    }
    }


    public test_final()
    throws ClassNotFoundException, SQLException
    {
    serviceURL = null;
    FinalUrl = null;
    UStr = null;
    cs = null;
    hs = null;
    testurl = null;
    i = 0;
    cnt = 0;
    SrNo = -1;
    Send_What_flag = "";
    pin_cnt = 0;
    error_cnt = 0;
    redir_errrmsg_cnt = 0;
    BT_Dev_cnt = 0;
    initComponents();
    try
    {
    local = LocalDevice.getLocalDevice();
    discoveryAgent = local.getDiscoveryAgent();
    System.out.println((new StringBuilder()).append("Local Device: ").append(local.getFriendlyName()).append(" : ").append(local.getBluetoothAddress()).toString()) ;
    local.setDiscoverable(0);
    giveConnection connobj = new giveConnection();
    conn = connobj.ConnectionType4Provider();
    try
    {
    connobj.Empty_BT_Table(conn);
    connobj.Empty_BT_Confirmation(conn);
    int n = connobj.Enter_info(conn);
    System.out.println((new StringBuilder()).append("n :").append(n).toString());
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    catch(ParseException ex)
    {
    ex.printStackTrace();
    }
    }
    catch(BluetoothStateException e)
    {
    message = "Local Device Not Found";
    return;
    }
    devicediscovery dd = new devicediscovery();
    }

    private void initComponents()
    {
    jLabel2 = new JLabel();
    jPanel1 = new JPanel();
    jButton1 = new JButton();
    jLabel1 = new JLabel();
    jLabel2.setIcon(new ImageIcon("C:\\btimage\\images\\bt_07.gif"));
    jLabel2.setAlignmentY(0.0F);
    jLabel2.setIconTextGap(0);
    jPanel1.setBackground(new Color(0, 0, 0));
    jPanel1.setAlignmentX(0.0F);
    jPanel1.setAlignmentY(0.0F);
    jPanel1.setMinimumSize(new Dimension(611, 370));
    jPanel1.setPreferredSize(new Dimension(611, 370));


    setDefaultCloseOperation(3);
    setBackground(UIManager.getDefaults().getColor("Bu tton.disabledShadow"));
    setCursor(new Cursor(0));
    setFocusCycleRoot(false);
    setFocusable(false);
    setFocusableWindowState(false);
    setResizable(false);
    setUndecorated(true);
    addComponentListener(new ComponentAdapter() {

    public void componentShown(ComponentEvent evt)
    {
    formComponentShown(evt);
    }

    final test_final this$0;


    {
    this$0 = test_final.this;

    }
    });
    addPropertyChangeListener(new PropertyChangeListener() {

    public void propertyChange(PropertyChangeEvent evt)
    {
    formPropertyChange(evt);
    }

    final test_final this$0;


    {
    this$0 = test_final.this;

    }
    });
    addContainerListener(new ContainerAdapter() {

    public void componentRemoved(ContainerEvent evt)
    {
    formComponentRemoved(evt);
    }

    final test_final this$0;


    {
    this$0 = test_final.this;

    }
    });
    addWindowListener(new WindowAdapter() {

    public void windowClosed(WindowEvent evt)
    {
    formWindowClosed(evt);
    }

    final test_final this$0;


    {
    this$0 = test_final.this;

    }
    });
    jButton1.setText("Stop");
    jButton1.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent evt)
    {
    jButton1ActionPerformed(evt);
    }

    final test_final this$0;


    {
    this$0 = test_final.this;

    }
    });
    jLabel1.setFont(new Font("Verdana", 1, 14));
    jLabel1.setText("BT");


    pack();
    }

    private void formWindowClosed(WindowEvent evt)
    {
    giveConnection connobj = new giveConnection();
    try
    {
    conn = connobj.ConnectionType4Provider();
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    try
    {
    int n = connobj.BT_Stop_Flag(conn);
    System.out.println((new StringBuilder()).append("n :").append(n).toString());
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    try
    {
    conn = connobj.ConnectionType4Provider();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    }

    private void jButton1ActionPerformed(ActionEvent evt)
    {
    giveConnection connobj = new giveConnection();
    try
    {
    conn = connobj.ConnectionType4Provider();
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    try
    {
    int n = connobj.BT_Stop_Flag(conn);
    System.out.println((new StringBuilder()).append("n :").append(n).toString());
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    try
    {
    conn = connobj.ConnectionType4Provider();
    int e = connobj.Empty_BT_Table(conn);
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    System.exit(1);
    }

    private void formComponentShown(ComponentEvent componentevent)
    {
    }

    private void formComponentRemoved(ContainerEvent containerevent)
    {
    }

    private void formPropertyChange(PropertyChangeEvent propertychangeevent)
    {
    }



    public void SendPin(int SrNo, int service_flag)
    {
    int transfer_flag = 0;
    pin_cnt = (int)(Math.random() * 10D);
    File pin_file = new File((new StringBuilder()).append("C:\\AddImage\\PIN\\").app end(PIN_imgs[pin_cnt].toString()).append(".JPG").toString());
    System.out.println((new StringBuilder()).append("pin cnt").append(pin_cnt).append("").append(PIN_imgs[pin_cnt].toString()).toString());
    String pin = PIN_imgs[pin_cnt].toString();
    System.out.println((new StringBuilder()).append("PIN").append(pin).toStrin g());
    giveConnection connobj = new giveConnection();
    try
    {
    conn = connobj.ConnectionType4Provider();
    System.out.println("Connection established....");
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    try
    {
    transfer_flag = ObjectPushPin(pin_file);
    System.out.println((new StringBuilder()).append("Object Push called ....transfer_flag :").append(transfer_flag).toString());
    if(transfer_flag == 1 && service_flag == 0)
    {
    int n = connobj.Enter_PIN(pin, conn);
    System.out.println("Enter PIN called ....1");
    System.out.println((new StringBuilder()).append("Enter PIN called ....n=").append(n).toString());
    Send_What_flag = "Content";
    } else
    if(transfer_flag == -1)
    {
    int n = connobj.Enter_PIN("-1", conn);
    System.out.println("Enter PIN called ....2");
    System.out.println((new StringBuilder()).append("Enter PIN called ....n=").append(n).toString());
    stop_bt();
    } else
    if(service_flag == -1)
    {
    int n = connobj.Enter_PIN("-2", conn);
    System.out.println("Enter PIN called ....3");
    System.out.println((new StringBuilder()).append("Enter PIN called ....n=").append(n).toString());
    stop_bt();
    }
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    System.out.println((new StringBuilder()).append("sql exception ....").append(ex.toString()).toString());
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    System.out.println((new StringBuilder()).append("sql exception ....").append(ex.toString()).toString());
    }
    }

    public void stop_bt()
    {
    giveConnection connobj = new giveConnection();
    try
    {
    conn = connobj.ConnectionType4Provider();
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    try
    {
    int n = connobj.BT_Stop_Flag(conn);
    System.out.println((new StringBuilder()).append("n :").append(n).toString());
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    try
    {
    conn = connobj.ConnectionType4Provider();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    System.exit(1);
    }


    //get the array of file path
    public void send_content(int SrNo, int service_flag, String File_path)
    {

    int transfer_flag = 0;
    // File content_file = new File(File_path);
    giveConnection connobj = new giveConnection();
    try
    {
    conn = connobj.ConnectionType4Provider();
    System.out.println("Connection established....");
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    }
    try
    {
    transfer_flag = ObjectPush(File_path);
    System.out.println((new StringBuilder()).append("object push called .....service flag: ").append(service_flag).append("Service flag end").toString());
    System.out.println((new StringBuilder()).append("Object Push called ....transfer_flag : ").append(transfer_flag).append("transfer flag end").toString());
    if(transfer_flag == 1 && service_flag == 0)
    {
    int n = connobj.Enter_Trans_Flag(transfer_flag, SrNo, conn);
    System.out.println("Enter PIN called ....1");
    System.out.println((new StringBuilder()).append("Enter PIN called ....n=").append(n).toString());
    } else
    if(transfer_flag == -1)
    {
    int n = connobj.Enter_Trans_Flag(-1, SrNo, conn);
    System.out.println("Enter PIN called ....2");
    System.out.println((new StringBuilder()).append("Enter PIN called ....n=").append(n).toString());
    } else
    if(service_flag == -1)
    {
    int n = connobj.Enter_Trans_Flag(-2, SrNo, conn);
    System.out.println("Enter PIN called ....3");
    System.out.println((new StringBuilder()).append("Enter PIN called ....n=").append(n).toString());
    }
    System.out.println("End of send content................");
    stop_bt();
    }
    catch(SQLException ex)
    {
    ex.printStackTrace();
    System.out.println((new StringBuilder()).append("sql exception ....").append(ex.toString()).toString());
    }
    catch(ClassNotFoundException ex)
    {
    ex.printStackTrace();
    System.out.println((new StringBuilder()).append("sql exception ....").append(ex.toString()).toString());
    }
    }

    public String WaitForVerificationFlag(int SrNo)
    {
    String verify_content = null;
    int flag = 0;
    try
    {
    giveConnection connobj = new giveConnection();
    conn = connobj.ConnectionType4Provider();
    System.out.println("In Wait For verification path..");
    do
    {
    if(flag != 0)
    break;
    System.out.println((new StringBuilder()).append("In Wait For verification path in while ...flag=").append(flag).toString());
    verify_content = connobj.get_Content_path(conn, SrNo);
    System.out.println((new StringBuilder()).append("In Wait For verification path...in if(RS!= null) in while.... verify_content=").append(verify_content).toString( ));
    if(!verify_content.equals("0"))
    flag = 1;
    } while(true);
    }
    catch(Exception ex)
    {
    System.out.println((new StringBuilder()).append("Error in Wait For verification path() Function.............").append(ex.toString()).toSt ring());
    }
    return verify_content;
    }


    //get the array of files
    public int ObjectPush(String filenames)
    {
    int flag = 0;
    String[] paths=filenames.split(";");

    for(int i=0;i<paths.length;i++)
    {
    File f1=new File(paths[i]);
    try
    {
    cs = (ClientSession)OBEXConnector.open(UStr);
    hs = cs.connect(cs.createHeaderSet());
    if(f1 != null)
    {
    InputStream is = new FileInputStream(f1);
    byte text[] = new byte[is.available()];
    is.read(text);
    is.close();
    hs.setHeader(1, f1.getName());
    hs.setHeader(66, "image");
    hs.setHeader(195, new Long(text.length));
    po = cs.put(hs);
    HeaderSet hs1 = po.getReceivedHeaders();
    po.openOutputStream().write(text);
    System.out.println("1 file sent");
    flag = 1;
    po.close();
    cs.disconnect(null);
    cs.close();
    cs = null;
    if(cs != null)
    {
    try
    {
    cs.disconnect(null);
    }
    catch(IOException ioe) { }
    try
    {
    cs.close();
    }
    catch(IOException ioe) { }
    cs = null;
    }
    System.out.println("Connection Closed");
    repaint(100L);
    }
    }
    catch(Exception e)
    {
    flag = -1;
    System.out.println((new StringBuilder()).append("Connection Interrupted").append(e.toString()).toString());
    if(cs != null)
    {
    try
    {
    cs.disconnect(null);
    }
    catch(IOException ioe) { }
    try
    {
    cs.close();
    }
    catch(IOException ioe) { }
    cs = null;
    }
    break;
    }
    System.out.println((new StringBuilder()).append("Flag in object push called....").append(flag).toString());

    }

    return flag;
    }



    public int ObjectPushPin(File f1)
    {int flag = 0;
    try
    {
    cs = (ClientSession)OBEXConnector.open(UStr);
    hs = cs.connect(cs.createHeaderSet());
    if(f1 != null)
    {
    InputStream is = new FileInputStream(f1);
    byte text[] = new byte[is.available()];
    is.read(text);
    is.close();
    hs.setHeader(1, f1.getName());
    hs.setHeader(66, "image");
    hs.setHeader(195, new Long(text.length));
    po = cs.put(hs);
    HeaderSet hs1 = po.getReceivedHeaders();
    po.openOutputStream().write(text);
    System.out.println("1 file sent");
    flag = 1;
    po.close();
    cs.disconnect(null);
    cs.close();
    cs = null;
    if(cs != null)
    {
    try
    {
    cs.disconnect(null);
    }
    catch(IOException ioe) { }
    try
    {
    cs.close();
    }
    catch(IOException ioe) { }
    cs = null;
    }
    System.out.println("Connection Closed");
    repaint(100L);
    }
    }
    catch(Exception e)
    {
    flag = -1;
    System.out.println((new StringBuilder()).append("Connection Interrupted").append(e.toString()).toString());
    if(cs != null)
    {
    try
    {
    cs.disconnect(null);
    }
    catch(IOException ioe) { }
    try
    {
    cs.close();
    }
    catch(IOException ioe) { }
    cs = null;
    }
    }
    System.out.println((new StringBuilder()).append("Flag in object push called....").append(flag).toString());
    return flag;

    }

    LocalDevice local;
    DiscoveryAgent discoveryAgent;
    Vector rd_vector;
    UUID uuids[] = {
    new UUID(4357L)
    };
    String serviceURL[];
    String FinalUrl;
    String btAddress;
    String UStr;
    ClientSession cs;
    HeaderSet hs;
    String testurl;
    Connection conn;
    BufferedReader br;
    Operation po;
    int R_Device_Cnt;
    int i;
    int selectedDev;
    int cnt;
    int attrSet[] = {
    256
    };
    int SrNo;
    String Date;
    String Time;
    String operator;
    String MACADD;
    int UploadFlag;
    String ContentPath;
    String Send_What_flag;
    String PIN_imgs[] = {
    "2902", "2610", "1206", "2606", "2609", "1810", "2580", "2712", "0912", "5573"
    };
    int pin_cnt;
    int error_cnt;
    int redir_errrmsg_cnt;
    int BT_Dev_cnt;
    String message;
    private JButton jButton1;
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JPanel jPanel1;





    }
    ----------------------------------------------------------------------
    2nd file name:giveconnection.java


    */import java.io.PrintStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.sql.Time;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.util.Date;



    public class giveConnection {

    public giveConnection()
    {
    conn = null;
    url = null;
    }

    public Connection ConnectionType4Provider()
    throws ClassNotFoundException, SQLException
    {
    Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jumpgames", "root", "webportal");
    return conn;
    }

    public int Enter_info(Connection Conn)
    throws SQLException, ParseException
    {
    Date d = new Date();
    java.sql.Date date = new java.sql.Date((new Date()).getTime());
    Time time = new Time((new Date()).getTime());
    DateFormat dateFormat = DateFormat.getTimeInstance(3);
    System.out.println((new StringBuilder()).append("date").append(date).toStr ing());
    System.out.println((new StringBuilder()).append("time").append(time).toStr ing());
    System.out.println((new StringBuilder()).append("dateFormat").append(dateF ormat).toString());
    Statement stmt = Conn.createStatement();
    String query = (new StringBuilder()).append("insert into bt_confirmation(BT_Devices_Flag,BT_Stop_Flag,BT_St art_Again_Flag,BT_Start_Flag,BT_Start_DateTime) values(0,0,0,1,'").append(date).append("')").toStr ing();
    int rows_affected = stmt.executeUpdate(query);
    stmt.close();
    return rows_affected;
    }

    public int insert_BT_Devices_Flag(Connection Conn)
    throws SQLException
    {
    System.out.println("inside insert_BT_Start_Flag");
    Date d = new Date();
    java.sql.Date date = new java.sql.Date((new Date()).getTime());
    Time time = new Time((new Date()).getTime());
    DateFormat dateFormat = DateFormat.getTimeInstance(3);
    System.out.println((new StringBuilder()).append("date").append(date).toStr ing());
    System.out.println((new StringBuilder()).append("time").append(time).toStr ing());
    System.out.println((new StringBuilder()).append("dateFormat").append(dateF ormat).toString());
    Statement stmt = Conn.createStatement();
    String query = (new StringBuilder()).append("update bt_confirmation set BT_Devices_Flag ='1' where BT_Start_Flag ='1' and BT_Start_DateTime ='").append(date).append("'").toString();
    int rows_affected = stmt.executeUpdate(query);
    stmt.close();
    return rows_affected;
    }

    public int BT_Stop_Flag(Connection Conn)
    throws SQLException
    {
    System.out.println("inside BT_Stop_Flag");
    Date d = new Date();
    java.sql.Date date = new java.sql.Date((new Date()).getTime());
    Time time = new Time((new Date()).getTime());
    DateFormat dateFormat = DateFormat.getTimeInstance(3);
    System.out.println((new StringBuilder()).append("date").append(date).toStr ing());
    System.out.println((new StringBuilder()).append("time").append(time).toStr ing());
    System.out.println((new StringBuilder()).append("dateFormat").append(dateF ormat).toString());
    Statement stmt = Conn.createStatement();
    String query = (new StringBuilder()).append("update bt_confirmation set BT_Stop_Flag ='1' where BT_Devices_Flag ='1' and BT_Start_DateTime ='").append(date).append("'").toString();
    int rows_affected = stmt.executeUpdate(query);
    stmt.close();
    return rows_affected;
    }

    public int Enter_Devices(String Bt_Name, String Bt_Add, Connection Conn, int SrNo)
    throws ClassNotFoundException, SQLException
    {
    int rows_affected = 0;
    Statement stmt = Conn.createStatement();
    String query = (new StringBuilder()).append("insert into BT_Table(SrNo,BT_Dev_Name,BT_Dev_Address) values(").append(SrNo).append(",'").append(Bt_Name ).append("','").append(Bt_Add).append("')").toStri ng();
    rows_affected = stmt.executeUpdate(query);
    stmt.close();
    return rows_affected;
    }

    public int Check_Select_Dev_Flag(Connection Conn)
    throws ClassNotFoundException, SQLException
    {
    int SrNo = -1;
    int return_val = -1;
    int Start_again = -1;
    System.out.println("select_dev_flag ... ");
    ResultSet RS = null;
    String query = null;
    query = "select bt_t.SrNo,bt_c.BT_Start_Again_Flag from BT_Table as bt_t,bt_confirmation as bt_C where bt_t.BT_Selected_Dev_Flag=1 or (bt_c.BT_Start_Flag=1 and bt_c.BT_Devices_Flag=0 and bt_c.BT_Start_Again_Flag=1)";
    Statement stmt = Conn.createStatement();
    RS = stmt.executeQuery(query);
    if(RS != null)
    for(; RS.next(); System.out.println("in "))
    {
    SrNo = RS.getInt(1);
    Start_again = RS.getInt(2);
    if(Start_again == 1)
    return_val = -2;
    else
    return_val = SrNo;
    System.out.println((new StringBuilder()).append("in select_dev_falg ... RS=").append(RS.getInt(1)).toString());
    }

    else
    return_val = -1;
    stmt.close();
    return return_val;
    }

    public void Close_RS(ResultSet RS)
    throws ClassNotFoundException, SQLException
    {
    RS.close();
    }

    public int Check_BT_Start_Again_Flag(Connection Conn)
    throws ClassNotFoundException, SQLException
    {
    int start_again_flag = -1;
    System.out.println("in give connection ... ");
    ResultSet RS = null;
    String query = null;
    query = "select BT_Start_Again_Flag from bt_confirmation where BT_Start_Flag=1 and BT_Stop_Flag=0";
    Statement stmt = Conn.createStatement();
    for(RS = stmt.executeQuery(query); RS.next(); System.out.println((new StringBuilder()).append("in give connection ... RS=").append(RS.getInt(1)).toString()))
    start_again_flag = RS.getInt(1);

    stmt.close();
    return start_again_flag;
    }

    public int Enter_PIN(String PIN, Connection Conn)
    throws ClassNotFoundException, SQLException
    {
    String Query = null;
    int rows_affected = 0;
    Statement stmt = Conn.createStatement();
    String query = (new StringBuilder()).append("update BT_Table set PIN_To_Send='").append(PIN).append("' where BT_Selected_Dev_Flag=1").toString();
    rows_affected = stmt.executeUpdate(query);
    stmt.close();
    return rows_affected;
    }


    public String get_Content_path(Connection Conn, int SrNo)
    throws ClassNotFoundException, SQLException
    {
    //String[] content_path;
    String content_path = null;
    String query = null;
    String query1 = null;
    int verification_flag = 0;
    String return_val = null;
    query = (new StringBuilder()).append("select PIN_Verification_Flag from BT_Table where BT_Selected_Dev_Flag=1 and SrNo=").append(SrNo).toString();
    //get content path from table and split it into array of strings
    query1 = "select BT_Content_Path from BT_Table where PIN_Verification_Flag=1";
    Statement stmt = Conn.createStatement();
    for(ResultSet RS = stmt.executeQuery(query); RS.next();)
    {
    verification_flag = RS.getInt(1);
    return_val = (new StringBuilder()).append("").append(verification_fl ag).toString();
    }

    stmt.close();
    if(verification_flag == 1)
    {
    Statement stmt1 = Conn.createStatement();
    for(ResultSet RS1 = stmt1.executeQuery(query1); RS1.next(); System.out.println((new StringBuilder()).append("Content Path=").append(return_val).toString()))
    {
    content_path = RS1.getString(1);
    return_val = content_path;
    }

    stmt1.close();
    }
    return return_val;
    }

    public int get_Content_Count(Connection Conn, int SrNo)
    throws ClassNotFoundException, SQLException
    {
    int fcnt = 0;
    String query = null;
    query = "select count(*) as fcnt from BT_Table where BT_Selected_Dev_Flag=1 and PIN_Verification_Flag=1";
    Statement stmt = Conn.createStatement();
    for(ResultSet RS = stmt.executeQuery(query); RS.next();)
    fcnt = RS.getInt(1);

    stmt.close();
    return fcnt;
    }

    public int Enter_Trans_Flag(int transaction_flag, int SrNum, Connection Conn)
    throws ClassNotFoundException, SQLException
    {
    String Query = null;
    int rows_affected = 0;
    Statement stmt = Conn.createStatement();
    String query = (new StringBuilder()).append("update BT_Table set Transaction_Flag=").append(transaction_flag).appen d(" where BT_Selected_Dev_Flag=1 and PIN_Verification_Flag=1 and SrNo=").append(SrNum).toString();
    rows_affected = stmt.executeUpdate(query);
    stmt.close();
    return rows_affected;
    }

    public int enter_pin(Connection Conn, String pin, int SrNum)
    throws SQLException
    {
    System.out.println("inside enter_pin ");
    int row = 0;
    Statement stmt = Conn.createStatement();
    String query = (new StringBuilder()).append("update bt_table set PIN_To_Send ='").append(pin).append("' where SrNo ='").append(SrNum).append("'").toString();
    row = stmt.executeUpdate(query);
    return row;
    }

    public int transfer_content(Connection Conn)
    throws SQLException
    {
    System.out.println("inside _BT_Start_Again_Flag");
    int flag = 0;
    Date d = new Date();
    java.sql.Date date = new java.sql.Date((new Date()).getTime());
    Time time = new Time((new Date()).getTime());
    DateFormat dateFormat = DateFormat.getTimeInstance(3);
    System.out.println((new StringBuilder()).append("date").append(date).toStr ing());
    System.out.println((new StringBuilder()).append("time").append(time).toStr ing());
    System.out.println((new StringBuilder()).append("dateFormat").append(dateF ormat).toString());
    Statement stmt = Conn.createStatement();
    String query = "update bt_table set Transaction_Flag ='1' where PIN_Verification_Flag ='1'";
    int n = stmt.executeUpdate(query);
    return n;
    }

    public int Empty_BT_Table(Connection Conn)
    throws ClassNotFoundException, SQLException
    {
    String Query = null;
    int rows_affected = 0;
    Statement stmt = Conn.createStatement();
    String query = "delete from BT_Table";
    rows_affected = stmt.executeUpdate(query);
    stmt.close();
    return rows_affected;
    }

    public int Empty_BT_Confirmation(Connection Conn)
    throws ClassNotFoundException, SQLException
    {
    String Query = null;
    int rows_affected = 0;
    Statement stmt = Conn.createStatement();
    String query = "delete from bt_confirmation";
    rows_affected = stmt.executeUpdate(query);
    stmt.close();
    return rows_affected;
    }

    Connection conn;
    String url;

    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Read Sun's tutorial on how to set the main class file in the jar file's MANIFEST file.

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,750
    Rep Power
    19

    Default

    Wow.
    Lots of unformatted code there...:)

    But yes, as said, it's all to do with the MANIFEST file.

  4. #4
    abhijit is offline Member
    Join Date
    Sep 2009
    Posts
    24
    Rep Power
    0

    Default

    I've already tried all the things with manifest file .
    but its not working..

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by abhijit View Post
    I've already tried all the things with manifest file .
    but its not working..
    Obviously you haven't tried 'everything' because it still isn't working; show your manifest and tell us where you stored it in your .jar file.

    kind regards,

    Jos

  6. #6
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    Here is what you do...go into the folder with your explorer that contains all of the .class files for that project...



    create a new folder in c:\deployed_java and copy all of the .class files to it...this way is easier
    copy all of the .class files to your new folder

    then once all the .class files are copied remembered which class is your entry point ...probably Main.class if it is netbeans

    in the command prompt change directory to cd deployed_java where all of your .class files should be now

    then type: jar cfe my_program.jar Main {<<<entrypoint}}}(< <<<if your entry class has another name replace it with Main here don't add the file extension just make sure it is a .class file) Main.class(you must include the entry class again at the list of classes) ....and all your other classes with spaces inbetween them...then that jar will execute on double click with javaw no shell
    Last edited by aaroncarpet; 11-19-2009 at 08:11 AM.

  7. #7
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    your post is awefull laced with spaces and i cant even get it to compile because there are alot of typos

  8. #8
    abhijit is offline Member
    Join Date
    Sep 2009
    Posts
    24
    Rep Power
    0

    Default

    Hi, thank u 4 ur reply
    i've follow the same procedure given by u but this time it's giving me another error.



    C:\deployed_java>jar cfm my_program.jar test_final
    java.io.FileNotFoundException: test_final (The system cannot find the file speci
    fied)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at sun.tools.jar.Main.run(Unknown Source)
    at sun.tools.jar.Main.main(Unknown Source)

    and when i tried by giving .class extention as:

    C:\deployed_java>jar cfm my_program.jar test_final.class

    java.io.IOException:invalid header field



    I'm totally confused , pls help me.

  9. #9
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    YOU TYPED C":\deployed_java>jar cfm my_program.jar test_final"


    try this>>>>"C:\deployed_java>jar cfe my_program.jar test_final test_final.class"

    is test_final your entry point(public static void main(String args[])? is the .class file compiled? is it in that folder(deployed java?)?
    recompile test_final.java and make sure you have a clean .class file



    PLUS I Messed with this code and it is JME and you are having a problem showing both JME Librarys and JSE libraries
    Last edited by aaroncarpet; 11-25-2009 at 05:43 AM.

  10. #10
    abhijit is offline Member
    Join Date
    Sep 2009
    Posts
    24
    Rep Power
    0

    Default

    thank u very much 4 ur quick concern..

    i've tried all the things but its still not working.

    cd:\deployed_java>jar cfe BT.jar test_final.class

    here e is not valid option.

    cd:\deployed_java>jar cfm BT.jar test_final.class

    giving the same error....

  11. #11
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    this is WRONG cd:\deployed_java>jar cfe BT.jar test_final.class
    this is RIGHT cd:\deployed_java>jar cfe BT.jar test_final test_final.class


    your main prolblem though is JME isn't recognizing JSE or vice versa

  12. #12
    abhijit is offline Member
    Join Date
    Sep 2009
    Posts
    24
    Rep Power
    0

    Default

    Hi , thnks again 4 reply

    Sir the command provided by u which is

    >>jar cfe BT.jar test_final test_final.class

    giving the error invalid option e

    then i've tried using

    >>jar cvf BT.jar test_final test_final.class giveConnection.class


    test-final : no such directory


    >>jar cvf BT.jar test_final.class giveConnection.class

    it's creating the jar file but when i clickm it , an error message box appear as

    "Failed to load main class attribute from C:\deployed_java\BT.jar"


    now i've created a manifest file in the same folder viz.,manifest.txt
    contents of manifest file are

    Main-Class: STARBT.test_final

    (it's ended with newline character)


    now i run the command

    C:\deployed_java>jar cvf BT.jar manifest.txt test_final.class giveConnection.class

    and when i click the jar file it is showing the same error(message Box).

    I'm not at all getting what i'm missing...

  13. #13
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    go to java.com and make sure you have the most current jre

  14. #14
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    The problems you are having have nothing to do with your Java version.
    Rather read
    Lesson: Packaging Programs in JAR Files (The Java™ Tutorials > Deployment)

    to find out how to create and use jar files so you don't have to guess how to do it.

  15. #15
    abhijit is offline Member
    Join Date
    Sep 2009
    Posts
    24
    Rep Power
    0

    Default

    jar cfe BT.jar test_final test_final.class

    here e option is not available in JDK 1.5, that's why it is giving me an error.

    now the problem is that whnt i try to run the jar file from command prompt
    it's giving the same error. and when i set the path from command prompt
    path="C:\Program Files\Java\jdk1.5.0_09\bin"; it's giving the proper o/p.

    where do i've to set the path so that i can run the jar file from anywhere w/o again & again setting path.

    i've also set the path vriable in
    Mycomputer->Advanced->Environment variables->path

    but it's still not working..

  16. #16
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,750
    Rep Power
    19

    Default

    So you've successfully created an executable jar now?
    And are trying to run it?

    What, exactly, are you giving as your command, and what is the error you're getting?

  17. #17
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    Weren't you saying that this program worked in netbeans? if it did then netbeans created a jar that you can move to an outside folder...it will be in the dist folder,,,,Copy and paste your system variable line

  18. #18
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,750
    Rep Power
    19

    Default

    Does netbeans automatically jar things up then?
    I'd have thought it was simply running the app directly from wherever it had compiled the class files to.

  19. #19
    aaroncarpet's Avatar
    aaroncarpet is offline Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    147
    Rep Power
    0

    Default

    Yeah, well i use 1.6 but running from the ide isn't the jar...the ide puts console output on the ide...but if you have built and compiled then one of the folders in your project will say dist and the jar will have the same name as your package... I just copy and paste it into a root folder of c: so I don't have to do all the cd commands and then you can execute that jar from command line and use memory management(-Xms -Xmx) java.exe or javaw.exe

  20. #20
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,750
    Rep Power
    19

    Default

    Actually, looking at my copy I just created an executable jar just by doing a build. It seems to have "jar-ing" as a default, setting up the Manifest for you based on whatever is marked as your main class. This is on 6.7.1. Haven't tried to run it, though.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 04-07-2009, 06:25 AM
  2. Replies: 0
    Last Post: 02-11-2009, 09:53 AM
  3. Replies: 7
    Last Post: 11-19-2008, 02:09 PM
  4. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 09:57 AM
  5. Replies: 7
    Last Post: 05-23-2008, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •