This discussion is archived
2 Replies Latest reply: Sep 2, 2013 6:03 AM by PhHein RSS

can't insert data into database table through .jar file

usman_noshahi Newbie
Currently Being Moderated

Hi ,

 

I am using Oracle database 10g

----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

 

operating system windows xp service pack 3.

And Netbeans IDE 7.2

 

I successfully created connection in ODBC(data source)  System DSN . with user name and SID

 

i downloaded CLASSES12.jar and place it in C:\oracle\product\10.2.0\db_1\BIN    directory , also set variable CLASSPATH in system environment .

bellow is the code that i am using

  String driver="sun.jdbc.odbc.JdbcOdbcDriver";
                String cs="jdbc:odbc:us";
                String user = "pms";
                String pwd = "pms";
                String sqlstmt="INSERT INTO JTEST VALUES("+ bill_no +","+ step +")";
                Connection con = null;
                Statement st = null;
                try
                {
                Class.forName(driver);
                }
                catch(Exception e)
                {
                System.out.println(e);
                }
                System.out.println("Driver loaded");
                try
                {
                con=DriverManager.getConnection(cs,user,pwd);
                System.out.println("Connected to the Oracle Database");
                st = con.createStatement();//creates a Statement object for sending SQL statements to the database.
                int updatecount=st.executeUpdate(sqlstmt);//return either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
                con.commit();    
                System.out.println(updatecount+" row inserted");
                }
                catch(Exception e)
                {
                System.out.println(e);
                }
                try
                {
                st.close();
                con.close();
                }
                catch(Exception e)
                {
                System.out.println(e);
                }

 

Problem:

 

problem is that when i run this code in NETBEANS , it inserts data perfectly in JTest table , but when i run this project from executable .jar file (double clicking) on the file it is not working ,

 

if i am missing something ?

 

usman

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points