Accessing Sql Server from AS400 Java program

Hi everybody,
I am trying to access Sql Server from an AS400 Java program. I have tried various Sql Server JDBC drivers including the Microsoft one but no luck yet. When i try to compile my Java program (with driver file in the classpath) it gives some errors on the driver jar file and also it throws out lots of unreadable text characters. This gave me a feeling that probably its a character coding issue with the jar file, so i tried ftp the file in binary mode as well as copying through the Operations Navigator. But still compilation is giving the same kind of errors.
Do I need to have some special JDBC Drivers compiled for AS400 specifically. My understanding was that Java is platform independent so any JDBC Type 4 driver will work.
We are running Java 1.3 on the AS400. Any help on this issue would be great.
Thanks
Inder

Thanks for the help. I am writing a Java program after a long time that's why was making that mistake. Now the program gets compiled correctly but on running the program i am getting the following error message:
java 001-0070: Exception JVAB544 not expected
/myjava/test/msbase.jar: 001-0050 Syntax error on Line 1: token ')' not expected
/myjava/test/msutil.jar: 001-0050 Syntax error on Line 1: token ')' not expected
/myjava/test/mssqlserver.jar: 001-0050 Syntax error on Line 1: token ')' not expected
I have no idea what is this error about. Though the same driver files don't give any error when running on a Windows machine.
Thanks

Similar Messages

  • How to read files on server from a java program?

    Hello,
    I am fairly new to JSP programming. I have an issue with reading files. I am trying to call method of a normal java file from a jsp program. The method I am trying to call does some IO operation on Files. I have the files in the same directory as my class files on server that is in WEB-INF/classes folder. In my java program, I am giving just the file name to open because the files and the classes are in the same directory. But this is not working.
    What exactly should I do to read a file from a java program, that is running on the server?
    Any help is appreciated.
    Thanks,
    Krishna

    String realFilePath = application.getRealPath("/WEB-INF/myFile.txt");
    File fileToOpen = new File(realFilePath);
    out.println(fileToOpen.getAbsolutePath() + ": exists? " + fileToOpen.exists());in this case "application" is a reference to the ServletContext.
    It is an implicit variable in a JSP. In a servlet:
    ServletContext application = getServletConfig().getServletContext();

  • Accessing SQL Server from Oracle

    I found an article:
    http:www.databasejournal.com/features/oracle/article.php/3442661
    It shows how to setup a connection from Oracle to SQL Server.
    I am new to Oracle Using SQL Loader and PL/SQL.
    I would like to use the SQL Loader in Oracle to load a table in SQL Server. It is my understanding that a ctl file is used and is called by an Oracle application.
    I would not have an Oracle application. I would like to use the ctl file to load the SQL Server table. Can someone point me on how to use the ctl file for SQL Server?
    Also, in PL/SQL would there be a connection string to connect to SQL Server when accessing a table.
    Is there a book or some documentation that would address the above?
    Thanks in Advance.

    that article shows you how to access SQL Server database through Oracle, therefore you have no need to use SQL Loader to load data from SQL Server bcos it can be queried directly by using simple select statement.
    If you want to load the data into Oracle just use CREATE TABLE ... AS SELECT ...
    in PL/SQL, what you need is the database link.
    Cheers,
    NH

  • Accessing oracle DB from a java program - question for oracle driver

    Hi,
    I have Oracle 10 G under vista on my desktop. I am trying to write a simple java program to access/update database tables. I saw in one of oracle example to import 2 packages - namely --- import oracle.jdbc.driver.*; import oracle.sql.*;
    Where do I find these 2 packages. Also I read some documentation to download drivers. I would like to use 2 drivers, the thin driver and the OCI driver. Can someone tell me where I can find these drivers and where do I copy these two drivers - so javac and java command can recognize it.
    I will greatly appreciate the help. Julia
    My program is as follows
    (It was working few years ago but things have changed now and I have Vista because my old machine died):
    import java.sql.*; // JDBC package
    //import com.inet.tds.JDBCRowSet;
    import java.util.*;
    import oracle.jdbc.driver.*;
    import oracle.sql.*;
    public class HomeDB
    run as follows:
    C:\Documents and Settings\MMM>cd \jj
    C:\john>set CLASSPATH=.;c:\oracle9i\classes12;%CLASSPATH%
    C:\john>javac HomeDB.java
    C:\john>java HomeDB
    King: 24000.0
    Kochhar: 17000.0
    De Haan: 17000.0
    Hunold: 9000.0
    Ernst: 6000.0
    Austin: 4800.0
    public static void main(String[] argv)throws SQLException
    Connection conn=null;
    try // may throw a SQLException
    conn = getConnection();
    doQuery (conn);
    catch (SQLException e)
    System.err.println(e.getErrorCode() + ": " + e.getMessage());
    finally // make sure the connection is closed
    if (conn != null) try {conn.close();} catch (SQLException e) {};
    //out.close(); // close PrintWriter stream
    private static Connection getConnection() throws SQLException
    String username = "scott";
    String password = "tiger";
    String url = "jdbc:oracle:thin:@localhost:1521:newora";
    // "jdbc:oracle:thin:@localhost:1521:COCKYJOB";
    Connection conn = null;
    String driver = "oracle.jdbc.driver.OracleDriver";
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    } catch ( ClassNotFoundException cnfex ) {
    System.err.println(
    "Failed to load JDBC/ODBC driver." );
    cnfex.printStackTrace();
    }catch (Exception e){
    e.printStackTrace();
    //DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    conn = java.sql.DriverManager.getConnection(url,username,password);
    conn.setAutoCommit(false);
    return conn;
    private static void doQuery (Connection c) throws SQLException
    // statement to be executed
    String query = "SELECT ename, job, mgr FROM EMP";
    Statement st = null;
    ResultSet rs = null;
    try // make sure the close statements are executed (in the finally block)
    // create the statement
    st = c.createStatement();
    // execute the query
    rs = st.executeQuery(query);
    // process results
    while (rs.next())
    // get the employee last name
    String eName = rs.getString("ename");
    String eJob = rs.getString("job");
    String eMgr = rs.getString("mgr");
    System.out.println("Emp Name:" + eName +
    "Job: " + eJob +
    "MGR: " + eMgr);
    finally // make sure the close statements are executed
    // close the result set if it exists
    if (rs != null) try {rs.close();} catch (Exception e) {};
    // close the statement if it exists
    if (st != null) try {st.close();} catch (Exception e) {};
    Edited by: user455788 on Dec 19, 2008 9:13 PM

    You can download the drivers from http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html.
    Note that oracle.jdbc.driver is desupported after 10.2, http://forums.oracle.com/forums/ann.jspa?annID=201, so you might want to consider using a DataSource to provide Connections.
    E.G.
    {message:id=2819114}

  • Accessing SQL Server from ORACLE using Transparent Gateway

    So I had downloaded the gateway installer and was following the guide here to set up the Transparent Gateway for SQL Server: http://www.orafusion.com/art_orahs.htm
    After I had created the database link, I was prompted the following error when trying to do a simple select statement from the SQL Server DB:
    >
    ORA-12154: TNS:could not resolve service name
    12154. 00000 - "TNS:could not resolve the connect identifier specified"
    *Cause:    A connection to a database or other service was requested using
    a connect identifier, and the connect identifier specified could not
    be resolved into a connect descriptor using one of the naming methods
    configured. For example, if the type of connect identifier used was a
    net service name then the net service name could not be found in a
    naming method repository, or the repository could not be
    located or reached.
    *Action:  
    - If you are using local naming (TNSNAMES.ORA file):
    - Make sure that "TNSNAMES" is listed as one of the values of the
    NAMES.DIRECTORY_PATH parameter in the Oracle Net profile
    (SQLNET.ORA)
    - Verify that a TNSNAMES.ORA file exists and is in the proper
    directory and is accessible.
    - Check that the net service name used as the connect identifier
    exists in the TNSNAMES.ORA file.
    - Make sure there are no syntax errors anywhere in the TNSNAMES.ORA
    file. Look for unmatched parentheses or stray characters. Errors
    in a TNSNAMES.ORA file may make it unusable.
    - If you are using directory naming:
    - Verify that "LDAP" is listed as one of the values of the
    NAMES.DIRETORY_PATH parameter in the Oracle Net profile
    (SQLNET.ORA).
    - Verify that the LDAP directory server is up and that it is
    accessible.
    - Verify that the net service name or database name used as the
    connect identifier is configured in the directory.
    - Verify that the default context being used is correct by
    specifying a fully qualified net service name or a full LDAP DN
    as the connect identifier
    - If you are using easy connect naming:
    - Verify that "EZCONNECT" is listed as one of the values of the
    NAMES.DIRETORY_PATH parameter in the Oracle Net profile
    (SQLNET.ORA).
    - Make sure the host, port and service name specified
    are correct.
    - Try enclosing the connect identifier in quote marks.
    Error at Line: 3 Column: 27
    >
    Here are my configuration files:
    initMSQL.ora
    >
    HS_FDS_CONNECT_INFO=webdatasvr:1433.InfoWeb
    HS_FDS_TRACE_LEVEL=OFF
    HS_FDS_RECOVERY_ACCOUNT=RECOVER
    HS_FDS_RECOVERY_PWD=RECOVER
    >
    listener.ora
    >
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC=
    (GLOBAL_DBNAME=UGCMAC)
    (ORACLE_HOME = C:\oracle\product\10.2.0\db_1)
    (SID_NAME=UGCMAC)
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = C:\oracle\product\10.2.0\db_1)
    (PROGRAM = extproc)
    (SID_DESC =
    (SID_NAME = MSQL)
    (ORACLE_HOME = C:\oracle\product\11.2.0\tg_1)
    (PROGRAM = dg4msql)
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    (ADDRESS LIST=
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1524))
    >
    tnsname.ora
    >
    UGCMAC =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = UGCMAC)
    EXTPROC_CONNECTION_DATA =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    (CONNECT_DATA =
    (SID = PLSExtProc)
    (PRESENTATION = RO)
    MSQL=
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1524))
    (CONNECT_DATA =
    (SID = MSQL)
    (HS=OK)
    >
    Can anyone assist me? thanks!

    Hi kgronau,
    >
    After changing a listener.ora file you need to STOP and START the listener to get the changes loaded. It looks like your listener is not serving the 1524 port which could be related to the fact that you didn't stop/start the listener after you've edited the listener.ora file.
    ... But as stated earlier - please do not use a 10.2 listener to start an 11g gateway. Instead configure the listener of the gateway home.
    >
    I did restart my listener under services.msc whenever I make the changes but there are no effect. Please also note that I can only find "OracleOraDb10g_home1TNSListener" under my services.msc. There is no 11.2 Listener. I did install the gateway and the installation was successful as far as I can tell. But perhaps because there's no 11.2 Listerner under my services.msc, could that mean it was a bad installation?
    >
    Next point is the tnsping you've used is 11.2. You need to make sure that you use the tnsping of the Oracle Database home as the database initiates the gateway connection so the database home tnsnames,ora needs the tns entry for the gateway.
    >
    My current PATH environment variables setting is as follow: C:\oracle\product\11.2.0\tg_1\bin;C:\oracle\product\10.2.0\db_1\bin; So perhaps, I just need to ensure the 10.2 ORACE home is the first?
    >
    As a final tip: There are so many web sites explaining how to configure DG4ODBC - many of them are faulty. If you need a reliable configuration, please have a look at "My Oracle Support" => How to Configure DG4ODBC (Oracle Database Gateway for ODBC) on Windows 32bit to Connect to Non-Oracle Databases Post Install     [Document 466225.1]     )
    >
    Is there a link?
    Edited by: omnri on 21-Jul-2011 23:59

  • Can't access SQL Server from a library [SMO Server throws exception]

    I have code that creates a SMO server object and then creates a set of tables in the target database. It works fine, if the code is in the main executable. If the code's in a library, it invariably throws an exception. The code's bog simple,
    SqlConnection connection = new SqlConnection(connectionStringTarget);
    Server server = new Server(new ServerConnection(connection));
    I can open the connection, so I know that there's nothing wonky there. (There's also the fact that it works if compiled into the exe.)
    Here's the error:
    Message: "Connection type is not valid."
    Source: "Microsoft.SqlServer.SqlEnum"
    Stack: "   at Microsoft.SqlServer.Management.Smo.ExecuteSql.InitConnection(Object con)\r\n   at Microsoft.SqlServer.Management.Smo.ExecuteSql..ctor(Object con)\r\n   at Microsoft.SqlServer.Management.Smo.ExecuteSql.GetServerVersion(Object con)\r\n   at Microsoft.SqlServer.Management.Smo.SqlServer.GetServerVersion(Object conn)\r\n   at Microsoft.SqlServer.Management.Smo.Environment.GetServerVersion(Urn urn, Object ci)\r\n   at Microsoft.SqlServer.Management.Smo.Environment.GetObjectsFromCache(Urn urn, Object ci)\r\n   at Microsoft.SqlServer.Management.Smo.Environment.GetData(Request req, Object ci)\r\n   at Microsoft.SqlServer.Management.Smo.Enumerator.GetData(Object connectionInfo, Request request)\r\n   at Microsoft.SqlServer.Management.Smo.Enumerator.Process(Object connectionInfo, Request request)"
    Target: {Void InitConnection(System.Object)}
    I'm developing using Visual Studio 2008, on Windows XP. The database that I'm trying to connect to is SQL Server 2005, and I'm pretty sure that it's current on its patches. I haven't been able to find any help on the "connection type is not valid" error, or why it doesn't work in a library. Any pointers would be appreciated.

    I received the same error message when using the following code:
    using System.Data.SqlClient;  
    using Microsoft.SqlServer.Management.Smo;  
    using Microsoft.SqlServer.Management.Common;  
    sqlConnection = new SqlConnection(DatabaseConnectionString);  
    ServerConnection serverConnection = new ServerConnection(sqlConnection);  
    svr = new Microsoft.SqlServer.Management.Smo.Server(serverConnection);  
    db = svr.Databases["master"]; 
    The "Connection type is not valid" exception would be thrown when trying to execute the last line of code above. In my case, the problem turned out to be with the references I had added to my project. I was using the following references in my project:
    Microsoft.SqlServer.ConnectionInfo  
    Microsoft.SqlServer.Smo  
    Microsoft.SqlServer.SmoEnum  
    Microsoft.SqlServer.SqlEnum 
    On closer inspection I found that I had inadvertently added version 10.0.0.0 of Microsoft.SqlServer.ConnectionInfo instead of version 9.0.242.0. The references for Microsoft.SqlServer.Smo, Microsoft.SqlServer.SmoEnum and Microsoft.SqlServer.SqlEnum were all using version 9.0.242.0. After removing version 10.0.0.0 of Microsoft.SqlServer.ConnectionInfo and replacing it with a reference to version 9.0.242.0 everything worked fine.
    For other people also experiencing this issue I would recommend checking the properties of the Microsoft.SqlServer.* references in your project to make sure they all have matching version numbers.

  • Whlile calling a Stored Procedure which is written in the Sql Server  from JSp java throws OutOfmemory error- Server used is Tomcat. Even after increasing the heap size the error has come

    while Using Tomcat it will throw out of memory for 50000 records and the weblogic throws Out of memory error for 2 lakshs records, and the Ibm server throws
    Out of memory error for 1 laksh records

    while Using Tomcat it will throw out of memory for 50000 records and the weblogic throws Out of memory error for 2 lakshs records, and the Ibm server throws
    Out of memory error for 1 laksh records

  • What are the different ways in accessing the SQL server from NWDS ?

    Hi Experts,
    Can anyone suggest the different ways for accessing the SQL server from NWDS.I also want to know whether any tool is available for accessing SQL server from Webdynpro java application in Netweaver development studio.
    I am currently using JDBC driver for accessing the SQL server from Webdynpro java application in NWDS.
    Regards,
    Krishna Balaji T

    Note - that no internet backup service has been proven to be safe and effective for backing up the iPhoto library - unless you personally have backup uyp an iPhoto library and restored it sucussfuly form one it should not be recommended - a large number of people have lost their photos trying it
    LN

  • Connect to MS Sql Server from Java Source

    Hi,
    Is there any way I could connect to ms sql server from Java source? I know I can call java source from function thats easy but what I really want is capability to connect to non-oracle(MS SQL server) from my java source and then call it from function.
    I don't know if JDBC driver for SQL server is even installed/available. Is there a way I could find it out form my IDE? I know sqlJ does compile but I have never used sqlj. help!!!
    Sinha

    You'll probably have better luck in a Java forum or a Microsoft forum.

  • How to call a PL/SQL procedure from a Java class?

    Hi,
    I am new to the E-BusinessSuite and I want to develop a Portal with Java Portlets which display and write data from some E-Business databases (e.g. Customer Relationship Management or Human Resource). These data have been defined in the TCA (Trading Community Architecture) data model. I can access this data with PL/SQL API's. The next problem is how to get the data in the Java class. So, how do you call a PL/SQL procedure from a Java program?
    Can anyone let me know how to solve that problem?
    Thanks in advance,
    Chang Si Chou

    Have a look at this example:
    final ApplicationModule am = panelBinding.getApplicationModule();
    try
         final CallableStatement stmt = ((DBTransaction)am.getTransaction()).
                                                                                         createCallableStatement("{? = call some_pck.some_function(?, ?)}", 10);
         stmt.registerOutParameter(1, OracleTypes.VARCHAR);
         stmt.setInt(2, ((oracle.jbo.domain.Number)key.getAttribute(0)).intValue());
         stmt.setString(3, "Test");
         stmt.execute();
         stmt.close();
         return stmt.getString(1);
    catch (Exception ex)
         panelBinding.reportException(ex);
         return null;
    }Hope This Helps

  • HOW TO INSERT DATA INTO SQL SERVER FROM MS ACCESS TABLE??

    NEED TO INSERT DATA INTO SQL SERVER FROM MS ACCESS TABLE.

    this is another method
    http://www.mssqltips.com/sqlservertip/2484/import-data-from-microsoft-access-to-sql-server/
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Problem accessing Sql server Procedure from Crystal with JDBC driver

    I have some Crystal reports using SQL Server procedures, most of them are working very well; however, I have 2 that have problems accessing sql server procedures. These reports are working using OLE DB connection without problem, but when I try to relocate the connection to JDBC Crystal generates an error like that the procedure not return records.
    The procedure is working with other products including OLE DB connections from crystal.
    What can I do?
    Thanks in Advance,
    JaimeC

    I am using:
    Crystal report 11 - 11.0.0.1282 and Crystal 2008 = 12.0.0.683
    SQL Server 2005 -  Microsoft SQL Server Management Studio Express     9.00.4035.00
    Windows XP
    I have discovered that the procedures create and work  temporary tables. In other cases when is working ok, the procedures have not working temporary tables.
    Thanks,
    Jaime Carrillo

  • Access SQL-Server Data from Oracle 10gXE

    Hello,
    I want to access sql-server data from oracle 10g XE. I need the same functionality provided by Sql-server by Linked Servers, by which we can query on any data source(oracle, Excel, Access).
    do, Oracle 10gXE provide us with same functionality ???
    any pointers ???

    Yes, it does work with Express Edition.
    Here is a thread from the XE forum with examples.
    Re: Database Link to MS Access
    They refer to a MS Access database, but the procedure is the same.
    Doug

  • To Restrict SQL account from accessing Sql server via SSMS

    Hi All,
    We are planning to tighten the security of our SQL Server.
    In the initial phase, we want to restrict all the SQL accounts(except sa) from accessing SQL Server via SSMS
    Since the SQL passwords are used in the connection strings(plain text) of our .NET Applications, developers are able to see it and they are accessing SQL server through SSMS with the credentials in the connection string.
    The requirement is, SQL accounts should only be accessing the databases through .NET applications and not through any other applications like SSMS, SQLCMD...etc
    1) We tried "Logon Trigger", but later we came to know that there is security breach in it.
    2) Application Roles - Password is plain text, again back to square one.
    We are looking for an alternate. Please share some ideas.
    Thanks & Regards,
    K.P.Senthil Kumar

    The basic presumption here is that there is on way you can tie a connection to an application as such. There is app_name(), but since this is passed from the application, the application can call itself whatever you want.
    As long as it is only a matter of keeping business users out, you can solve the issue with some three-tiered solution. Either by having a true middle layer, or just having a web server, or the application running on Terminal Server or Citrix.
    But you want to keep the developers out who work with the code. That makes it difficult to lock them out of the middle layer.
    Then again, you say "our SQL Server" is that singular? Don't you have more than one SQL Server? One for developement, one for test and one for production? If you only want to keep the devs out from development, you have different usernames
    and password for different environments, and they are read from config files. The config files for production should be well-protected.
    By the way, only permitting sa from logging in from SSMS is bad idea. Rather, you should disable sa, and everyone should log in with their individual Windows account. And those who should perform system-administration tasks should be member of sysadmin.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to access Sql Server Express installed on Virtual PC from Host?

     
    I have SQL Server Express 2008 R2 installed on Virtual PC. and on my Host machine i have SQL Server 2008 R2 ( Enterprise Version) installed.
    Since Management studio that comes with SQL express does not support SQL profiler, i want to access SQL Server Express from the Host machine’s management studio which has SQL profiler.
    But I could access it using VM’s ip address & instance name

    Hi lax,
    Follow below steps in your Virtual Machine:
    1. Allow remote connections to this server
    The first thing you want to check is if Remote Connections are enabled on your SQL Server database. In SQL Server 2008 you do this by opening SQL Server 2008 Management Studio, connect to the server in question, right click the server and open the Server Properties.
    Navigate to Connections and ensure that Allow remote connections to this server is checked.
    2.  Protocols for MSSQLServer
    The next good thing to check is the SQL Server Network Configuration. Open the SQL Server Configuration Manager, unfold the node SQL Server Network Configuration and select Protocols for MSSQLServer (or whatever the name of your SQL Server instance is). Make
    sure that TCP/IP is enabled.
    3. The Firewall
    If there is still no communication happening between your computer and the remote SQL Server you most likely need to configure your firewall settings.
    A good first step is to figure out which port is being used by TCP/IP (and which you need to open in your firewall). You can do this by right clicking TCP/IP and selecting Properties. Click on the tab IP Addresses .
    That was easy enough and all there is left to do is to allow inbound TCP/IP traffic on Port 1433 in your firewall. In Windows 7 this works something like this. Open the Control Panel and navigate to Windows Firewall. Click on Advanced Settings on the left hand
    side and you should see the Windows Firewall with Advanced Security. Select the Inboud Rules on the left hand side and click on New Rule on the right hand side. This opens the New Inbound Rule Wizard which you can use to allow inbound traffic on Port 1433
    for TCP/IP.
    For more information, please refer to
    http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx.
    In host machine:
    After you have done steps above, you could use the SQL Server Management Studio in the host machine to connect the SQL Server Express R2 in Virtual PC. If you installed a default instance in Virtual PC, you could use VirtualComputerName to login the SQL
    Server database engine. If you installed a named instance in Virtual PC, you could use VirtualComputerName\InstanceName to login the SQL Server database engine.
    Thanks,
    Maggie
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.

Maybe you are looking for