Solved

source code links

Posted on 2001-06-26
3
188 Views
Last Modified: 2011-09-20
Anyone can give links that give library system sourcode in JAVA.
Or source code of java of any systems that connect to  MS. Access or SQL server database with add, delete, update or search function.
0
Comment
Question by:anwar13
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
wgilster earned 100 total points
ID: 6228363
To run my example you will need to create a Data Source Name on your machine called 'AccessTestDSN'.  You can use any Access, SQL database you want, my example uses a table in the database called 'TestTable'.


package classes;
import java.sql.*;

public class TestServer
{
  static
  {
      try  {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      }
      catch (Exception e) {
          System.err.println(e);
      }
  }

  public static void main(String args[]) {
      Connection conn=null;
      Statement stmt=null;
      String sql="";
      try {
          conn=DriverManager.getConnection("jdbc:odbc:AccessTestDSN","","");
          stmt=conn.createStatement();
          sql="INSERT INTO [TestTable] (FIELD_NAME1 FIELD_NAME2 FIELD_NAME3) VALUES (100,'String Value',200)";
          stmt.executeUpdate(sql);

      }
      catch (Exception e){
          System.err.println(e);
      }
      finally {
          try{
              stmt.close();
              conn.close();
              stmt=null;
              conn=null;
          }
          catch(Exception e){}
      }
  }
}
0
 

Author Comment

by:anwar13
ID: 6231547
Thank you....
0
 

Author Comment

by:anwar13
ID: 6238114
wgilster:

package classes;
import java.sql.*;

public class TestServer
{
 static
 {
     try  {
       
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     }
     catch (Exception e) {
         System.err.println(e);
     }
 }

 public static void main(String args[]) {
     Connection conn=null;
     Statement stmt=null;
     String sql="";
     try {
       
conn=DriverManager.getConnection("jdbc:odbc:AccessTestDSN","","");
         stmt=conn.createStatement();
         sql="INSERT INTO [TestTable] (FIELD_NAME1
FIELD_NAME2 FIELD_NAME3) VALUES (100,'String
Value',200)";
         stmt.executeUpdate(sql);

     }
     catch (Exception e){
         System.err.println(e);
     }
     finally {
         try{
             stmt.close();
             conn.close();
             stmt=null;
             conn=null;
         }
         catch(Exception e){}
     }
 }
}


I compiled it without any errors...but when i run it
with
c:\java TestServer.class

the error comes out like:

Exception in thread "main"
java.lang.NoClassDefFoundError: TestServer/class

I am new in JAVA, so does it have to do with JDBC, I
don't know whether i have JDBC or not, i am using
windows2000.

regards,
anwar13
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question