The JDBC jar file is generally downloaded from the DB manfacturer's site, for example http://www.mysql.com , http://www.microsoft.com , http://www.ibm.com , etcetera. A self-respected manfacturer usually also have extensive documentation at their site how to use this jar, how to connect, how to query and how to process results. Look around at their sites.
For generic JDBC stuff, just read the Sun's official JDBC tutorial which you can find here: http://java.sun.com/docs/books/tutorial/jdbc/
Sorry for not explaining my problem more precise.
Well I'm using SQL Server 2005 from MS and I'll show you a program that works when it isn't in a jar file but when it is it doesn't work at all.
import java.sql.*;
import java.io.*;
public class SQL
{
public static void main(String[] args)
{
try
{
String strKnapp = "Hej";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost;user=Villex;password=viktor;databaseName=dbMusik";
Connection con = DriverManager.getConnection(connectionUrl);
String sql = "INSERT INTO FileName VALUES (?) ";
PreparedStatement stmnt = con.prepareStatement(sql);
stmnt.setString(1, strKnapp);
stmnt.executeUpdate();
con.close();
}
catch(Exception exc)
{
}
}
}
> Sorry for not explaining my problem more precise.
> Well I'm using SQL Server 2005 from MS and I'll show
> you a program that works when it isn't in a jar file
> but when it is it doesn't work at all.
There a number of problems with your code like not closing your statement and having an empty catch block.
But your real problem is classpath related.
Don't suppress exceptions and add at least e.printStackTrace() to the catch block. Big change that you will see a ClassNotFoundException for the com.microsoft.sqlserver.jdbc.SQLServerDriver then. If this is the case, you need to specify the JDBC driver in the class-path of the manifest.mf of the JAR file.
So this is my error message...
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at SQL.main(SQL.java:14)
Hello, not sure if this is similar, but I'm having problems with running my java applications once they have been packet into jar files.I am using an external jar file as a library... all is fine within the compiler, but once exported it doesn't want to work...
I think I know the problem... the problem is that the packet jar file can't see the libraries within the external jar file... I have checked the classpath file and its pointing to the correct place, but it doesn't see it...
Do you have any idea on what I'm doing wrong?