Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Unhappy how to configure DSN....??

    good morning ppl

    i have my data base in SQL Server 2008 and this data base is remote data base i have tried connecting to the data base using DSN in a window machine its runs successfully and the code given below is the same code which works on window machine using DSN!!!


    can any one help me out if i want to deploy the same class in Linux Redhat and how to configure DSN in Linux Redhat!!!


    The Code:


    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;

    public class ABC
    {
    public static Connection con;
    public static PreparedStatement ps;
    public static ResultSet rs;
    public static void main(String[] arg)
    {
    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:<DSN REFRENCE>","<USER NAME>","<PASSWORD>");
    ps = con.prepareStatement("Select * from <DATABASE NAME>.dbo.<TABLE NAME> where ClientUserId=? and ClientPasswd=?");
    ps.setString(1,"swapnil");
    ps.setString(2,"swapnil");
    rs=ps.executeQuery();
    ResultSetMetaData rsmd = rs.getMetaData();

    if(rs.next())
    {
    for(int i = 1;i <=rsmd.getColumnCount();i++)
    {
    System.out.println(rs.getString(i));
    }

    System.out.println("Login Successfull..");

    }
    else
    System.out.println("Login Unsuccessful...");
    }
    catch(Exception e)
    {
    System.out.println(e);
    }

    }
    }



    this code runs successfully on window machine but when the same code is compiled on Redhat there is no error while creating its object file but since i have no DNS the following error is returned!!!!!


    The Error:


    java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}



    so can any one help me how to Configure DSN in Linux Redhat???

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    That has nothing to do with a DSN. That has to do with the fact that you are using GCJ (Gnu Java). Download and install a proper JRE (and make sure to change the /usr/bin/java link and other java related links.

    However, you would stll need to have the ODBC Driver for Linux for SQL Server installed (somehow I doubt that you do). You would be much, much, much better off using the SQL Server JDBC Driver (either one downloaded from MS, although I have heard it is not completely compliant, or at least has problems, or, even better, google for and download the jTDS Driver for SQL Server).

  3. #3
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default

    my other java programs are running on on the machine!!

    including jakarta-tomcat-5.0.28

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    And? That means nothing. You are trying to use the JDBC-ODBC Bridge here, and that is not included (at least not under that class name) in GCJ. And, that also does not mean that "those other applications" are using the Bridge (or the GCJ for that matter), or that you have any ODBC Drivers installed. I fail to see your point.

  5. #5
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default

    pls tell me wat exactly i have to do??

    again!!

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    How are you executing your class.

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    What, exactly, you want to do, is to download and use the JDBC Driver, and not the JDBC-ODBC Bridge. If you want to use the Bridge, then you need to install the SQL Server ODBC Driver on your Linux machine (and there is probably a large license cost for it). Then, you also need to make sure that you are using a real JRE (not GCJ). the easiest way to do that is to make sure that one is installed then change all of the /usr/bin links that have anything to do with java.

    Edit: Using the JDBC Driver means, of course, changing the Class.forName line and the URL and making sure to include that Driver on the classpath.
    Last edited by masijade; 05-17-2010 at 03:00 PM.

  8. #8
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default

    gcj --main=ABC -o ABC ABC.java

    this is the command i use to compile java code!!


    and i run the program using this command ./ABC

    i have already install java in /usr/java/jdk1.6.0_20


    and also pls tell me how a java program can be run without using GCJ!

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Uhm, by actually using the Java you have installed, maybe.
    Java Code:
    /usr/java/jdk1.6.0_20/bin/javac ABC.java
    to compile the file and then
    Java Code:
    /usr/java/jdk1.6.0_20/jre/bin/java ABC
    to execute the file.

  10. #10
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default

    ok fine the code runs on jdk too!!!

    but can i ask u some thing will it be better to run program through GCJ ? or using jdk??


    because the code is required to give maximum efficiency!!since code has to genrate a real time data!!

    rest regarding jdbbc driver i even dont know how and where to get it from and how to use it!!

  11. #11
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    What have I said all along about (and what have you yourself noticed while) attempting to use GCJ? Don't. Also, you won't be able to do anything truly "real-time" in Java unless you get "Java RealTime" which is a licensed JDK that is not inexpensive. And any program you've written using the normal JDK is almost guaranteed to fail using JavaRT, but not because of the language. Then again, I can about guarantee that you don't understand the implications of the term "real-time" and you simply mean "near-time".

    As far as how to get the driver, see this.

    And, hopefully, you know how to use the CLASSPATH if you are programming in Java. If not, learn how. That is something every programmer needs to know. As was the rest of the advice given in this thread, so far.

  12. #12
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default

    ok let us not consider the case to be real time!!

    wat all i need is tat my java code should run most efficiently!!!


    regarding class paths if m not soo good at it i will be for sure more i will practice more!

  13. #13
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default

    ok now i am some how able to set class bath for the driver but still there is an error in the above given code its says java.lanag.NullPointerException!!!!


    and after debugging i have found tat Connection Object con has null value!!!!

    since i have IP,PORT,USERNAME and PASSWORD


    wat will be the Connection String???

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default

    For con to be coming back null I would have expected getConnection() to throw an exception. Are you ignoring exceptions by any chance?

  15. #15
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default

    @Tolls


    bro as u can c in above given code i have kept getConnection() in the Try catch block!!

  16. #16
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default

    @masijade


    i have added jar to /usr/java/jdk1.6.0_20/lib/sqljdbc4.jar

    and fired the following command

    #export CLASSPATH=/usr/java/jdk1.6.0_20/lib/sqljdbc4.jar

    #javac ABC.java
    #java ABC

    and now i am returned with the following error

    Exception in thread "main" java.lang.NoClassDefFoundError: sql
    Caused by: java.lang.ClassNotFoundException: sql
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    Could not find the main class: sql. Program will exit.


    i have checked the code in windows machineit is running there!!!

    and the new code is now.....


    THE CODE:


    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;

    public class ABC
    {
    public static Connection con;
    public static PreparedStatement ps;
    public static ResultSet rs;
    public static void main(String[] arg)
    {
    try
    {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    con=DriverManager.getConnection("jdbc:sqlserver://<I.P>:<PORT>","<USER NAME>","<PASSWORD>");
    ps = con.prepareStatement("Select * from <DATABASE NAME>.dbo.<TABLE NAME> where ClientUserId=? and ClientPasswd=?");
    ps.setString(1,"swapnil");
    ps.setString(2,"swapnil");
    rs=ps.executeQuery();
    ResultSetMetaData rsmd = rs.getMetaData();

    if(rs.next())
    {
    for(int i = 1;i <=rsmd.getColumnCount();i++)
    {
    System.out.println(rs.getString(i));
    }

    System.out.println("Login Successfull..");

    }
    else
    System.out.println("Login Unsuccessful...");
    }
    catch(Exception e)
    {
    System.out.println(e);
    }

    }
    }

  17. #17
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, hopefully you don't actually have a space in the name as shown here "SQLSer verDriver".

    And as far as the rest goes, if it turns out to be a simple classpath problem, I am not going to get into trying to explain how to configure and use classpaths properly. That always turns into either a holy war or an exercise in frustation and I am not going through it again.

  18. #18
    bonjovi4u is offline Member
    Join Date
    Mar 2010
    Posts
    28
    Rep Power
    0

    Default

    well now i have also figured out the whole problem is about confugring jdk on linux machine and since this is my first time!!!


    i have been trying to configure it from last 18 hrs!!

    so my friend i dont think u will be as frustated as me!!

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

    Default

    But your current problem is about providing the location of your sqljdbc4.jar to your run command.
    Use the -cp flag for that.

  20. #20
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by bonjovi4u View Post
    well now i have also figured out the whole problem is about confugring jdk on linux machine and since this is my first time!!!


    i have been trying to configure it from last 18 hrs!!

    so my friend i dont think u will be as frustated as me!!
    Except that you will only get frustated this once. Once I start getting into "helping" with classpaths again, I will be frustated continously, as they never stop, and they usually take days to resolve properly, as advice is ignored, or muddled because multiple people give differing advice (and much of it wrong, or at least, misadvised), and it is just not worth it. All I can say is, find someone who actually knows it and can stand beside you and explain it to you.

Page 1 of 2 12 LastLast

Similar Threads

  1. How to configure jmf in net beans
    By ishan in forum NetBeans
    Replies: 0
    Last Post: 01-08-2010, 06:44 AM
  2. Configure Apache in netbeans
    By mecrazycoder in forum New To Java
    Replies: 0
    Last Post: 07-01-2009, 07:20 AM
  3. Can we configure MS-SQL server in Netbeans?
    By makpandian in forum NetBeans
    Replies: 0
    Last Post: 05-19-2009, 07:42 AM
  4. configure smslib in Eclipse
    By javanese in forum Eclipse
    Replies: 1
    Last Post: 03-01-2009, 04:49 PM
  5. Configure Classpath
    By Doctor Cactus in forum New To Java
    Replies: 3
    Last Post: 01-08-2009, 01:11 PM

Posting Permissions

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