Accessing MS Sql Server with Java classes - problem connecting to socket

I found an example at this location which uses java classes to connected to MS Sql Server.
http://search400.techtarget.com/tip/1,289483,sid3_gci1065992,00.html
--bummer - it is a login location - so I will include the article
Anyway, the example is using Websphere, but I am still on Jbuilder (will get wsad soon). So I planted the classes from the example in
C:\Borland\JBuilder\jkd1.4\jre\lib\ext\...the classes
Then I copied the code from the example to my jpx project and got an error that it could not connect to the socket. The only thing I changed in the code was the connection string:
--original string from example:
Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://1433", "");
I was getting an error with the 2 argument version of DriverManager - and the second argument here was empty (properties argument). Here was my connection string:
Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://Myserver:1433;User=sa;Password=");
I am only using the 1 argument version of DriverManager. Note that the password=" is blank because my RnD workstation is standalone - no one accesses the sql server except me - so no password. I also left out the last semicolon I noticed. Any suggestions appreciated how I could fix this.
Thanks
source of article:
http://search400.techtarget.com/tip/1,289483,sid3_gci1065992,00.html
iSeries 400 Tips:
TIPS & NEWSLETTERS TOPICS SUBMIT A TIP HALL OF FAME
Search for: in All Tips All search400 Full TargetSearch with Google
PROGRAMMER
Sample code: Accessing MS SQL Server database from the iSeries
Eitan Rosenberg
09 Mar 2005
Rating: --- (out of 5)
Nowadays with the help of Java the iSeries can be integrated with other databases quite easy. This tip shows you how. The code included here uses the free Microsoft driver that can be downloaded from here. (SQL Server 2000 Driver for JDBC Service Pack 3)
If your SQL server does not include the Northwind Sample Database you can find it here.
http://www.microsoft.com/downloads/details.aspx?familyid=07287b11-0502-461a-b138-2aa54bfdc03a&displaylang=en
The download contains the following files:
msbase.jar
mssqlserver.jar
msutil.jar
Those files needs to be copied to the iSeries directories (/home/r_eitan/ExternalJARs).
Here's the directory structure (on the iSeries) for this sample:
/home/r_eitan/ExternalJARs - Microsoft files (msbase.jar,mssqlserver.jar,msutil.jar)
/home/r_eitan/JdbcTest02 - My code (Main.java,Main.class)
The Java code
import java.sql.*;
import java.io.*;
class Main {
* Connect to Microsoft SQL server and download file northWind.products as tab
* seperated file. (products.txt)
public static void main(String args[]) {
try {
PrintStream outPut = new PrintStream(new BufferedOutputStream(new FileOutputStream("products.txt")));
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://1433", "");
Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://Myserver:1433;User=sa;Password=");
System.out.println("Connection Done");
connection.setCatalog("northWind");
String sqlCmdString = "select * from products";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sqlCmdString);
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int columnCount = resultSetMetaData.getColumnCount();
// Iterate throught the rows in resultSet and
// output the columns for each row.
while (resultSet.next()) {
for (int index = 1; index <=columnCount; ++index)
String value;
switch(resultSetMetaData.getColumnType(index))
case 2 :
case 3 :
value = resultSet.getString(index);
break;
default :
value = """ + resultSet.getString(index) + """;
break;
outPut.print(value + (index < columnCount ? "t" : ""));
outPut.println();
outPut.close();
resultSet.close();
connection.close();
System.out.println("Done");
catch (SQLException exception)
exception.printStackTrace();
catch (Exception exception)
exception.printStackTrace();
--------------------------------------------------------------------------------------------------

My guess is that the server's host name isn't right. It necessarily (or even usually) the "windows name" of the computer. Try with the numeric IP address instead (type "ipconfig" to see it).
First aid check list for "connection refused":
- Check host name in connect string.
- Check port number in connect string.
- Try numeric IP address of server host in connect string, in case name server is hosed.
- Are there any firewalls between client and server blocking the port.
- Check that the db server is running.
- Check that the db server is listening to the port. On the server, try: "telnet localhost the-port-number". Or "netstat -an", there should be a listening entry for the port.
- Try "telnet serverhost the-port-number" from the client, to see if firewalls are blocking it.
- If "telnet" fails: try it with the numeric ip address.
- If "telnet" fails: does it fail immediately or after an obvious timeout? How long is the timeout?
- Does the server respond to "ping serverhost" or "telnet serverhost" or "ssh serverhost"?

Similar Messages

  • How to invoke a stored procedure on MS Sql Server with Java?

    I started writing Enterprise Java Beans and created an ODBC dsn with MS Sql Server 2000 which I can access using jdbc:odbc:mySqlDSN. This all works fine using Java Sql Statements. What kind of Java/Java Sql statement can I use to invoke a stored procedure on the Sql Server? Is it possible to use ADO/ADO command objects with Java? Is it possible to import/implement Mdac2.6 ActiveX data objects libary in Java?
    Thanks

    Thanks all for your replies. I will search the api for callable statements. I am curious though, the reply that suggests using a prepared statement - can I put the name of a stored procedure in a prepared statment or is this just suggestions an action query like Insert Into, Update, Delete? Like with ADO you can say
    cmdObject.CommandType = adStoredProcedure
    cmdObject.CommandText = "NameOfStoredProc"
    cmdObject.ExecuteNonQuery()
    Once I am calling/importing/implementing the proper libraries/interfaces in Java, can a prepared statement reference a stored procedure as above?
    Thanks

  • Any way of importing from Access to SQL Server?

    I have a huge store of information in Access. But now I'm required to use SQL Server.
    Is there any way of importing the information from Access to SQL Server by Java programming?
    Or is there a manual way of doing that?
    Thank you in advance.

    I need to use Java because this is for a client. I
    can't expect the client to follow those steps. As a
    result, I want to create something simple for the
    client to convert from Access to SQL Server.
    Any other way of doing that?
    That argument does not make sense.
    There is no way that a 'client' is going to be able to manage MS SQL Server without understanding how it works. MS SQL Server is a complex database and requires at least some dedicated support, even if it is only part time.
    For example consider the following:
    -MS Access does not have a log file. MS SQL Server does. How is the log file going to be sized?
    -If the log file fills up (like for a run away query) MS SQL Server comes to a screeching halt. How is that problem going to be fixed?
    Now maybe you are going to provide that support, which means you can run those scripts. Or the client is going to support it in which case they need to have someone who understands it - and they will need to know how to run those scripts (since it is rather basic knowledge.)

  • How to insert data from access to sql server ?

    How to insert data from access to sql server ?
    Please help me
    thanks

    phamtrungkien wrote:
    How to insert data from access to sql server by JAVA?The first four words of my last post:
    masijade wrote:
    JDBC with two connectionsGet a resultset from the jdbc-odbc bridge access connection, cycle through it and add batch insert commands to the jdbc connection to sql server. Give it a try and if the code has an error, then post your code ans ask a question.
    The real question, though, is why you think it absolutely necessary to use Java for this.

  • I want to impersonate user when I access Microsoft SQL Server from powershell

    Hi,
    Actually I have to perform some SQL operation on my MSSQL server database. but problems is that I have given all credentials (windows fix login/password which can access database) in connection string. but when I execute the script then it is always using
    my windows login and password and then giving error that not able to connect with it.
    My personal windows credentials does not have access to my enterprise database that is why I am using service ID.
    I came to know that I have to do user impersonation of user when i access database but how to do that?? can you guys give me the syntax for that as i have to perform all sql operation using impersonation.
    Please reply me as soon as possible as i stuck since long
    Vipul Mistry Sr. Embedded Engineer www.eInfochips.com

    Hi Guys,
    thanks a lot for your support and replies but I found the solution. With below code i was able to do my task and I used $AuthType =3 for my purpose. Hope this will help others also.
    $varDBServer = "N0SQL104,1675"
    $varDBInstance = ""
    $varDBSchema = "Data_Dev"
    $varDBUser = "S0060VMSD"
    $varDBPassword = "SDCFG345D"
    #### Choose authentication type (0=SSO, 1= SQL, 2=Domain)
    $AuthType = 3
    #### Load the required assembly for sql server administration
    #### Requieres SQLServerNativeClient, SQLSysClrTypes and SharedManagementObjects
    [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
    $varSQLServer = New-Object -typeName Microsoft.SqlServer.Management.Smo.Server -argumentList "$varDBServer\$varDBInstance"
    switch ($AuthType) {
    1 {
    #### Access the SQL-Server with your current credentials (pass-through)
    $varSQLServer.ConnectionContext.LoginSecure = $true
    2 {
    #### Access the SQL-Server with SQL-Server credentials in mixed mode authentications
    $varSQLServer.ConnectionContext.LoginSecure = $false
    $varSQLServer.ConnectionContext.Login = $varDBUser
    $varSQLServer.ConnectionContext.Password = $varDBPassword
    3 {
    #### Access the SQL-Server with given domain user credentials
    $varSQLServer.ConnectionContext.LoginSecure = $true
    $varSQLServer.ConnectionContext.ConnectAsUser = $true
    $varSQLServer.ConnectionContext.ConnectAsUserName = $varDBUser
    $varSQLServer.ConnectionContext.ConnectAsUserPassword = $varDBPassword
    } default {
    Write-Host "Please select an authentication type: 0=SSO, 1= SQL, 2=Domain"
    exit -1
    #### Try connection to SQL-Server with given parameters
    Write-Host "`nTry connection to SQL-Server with given parameters`n"
    try {
    $varBuildOfSQLServer = $varSQLServer.Version.get_Build()
    Write-Host "Build of SQL-Server '$varDBServer' is $varBuildOfSQLServer"
    } catch {
    Write-Host "ERROR: Cannot access SQL-Server '$varDBServer'. Exit script!"
    exit –1
    Vipul Mistry Sr. Embedded Engineer www.eInfochips.com

  • How to access sql server using java script

    Hi, Is it possible to connect to sql server in java script. I'm using microsoft jdbc driver for connectivity to sql server.
    Thanks

    Hi, Is it possible to connect to sql server in java
    script. I'm using microsoft jdbc driver for
    connectivity to sql server.If you want to ask about Javascript, you are in the wrong place. Go and find some JavaScript forum. Actually, you could connect to database from javascript using Ajax or the like mainly because you could have Java code behind the scenes, but then that too is not something I would want to discuss here. So, go find the correct place for the topic.

  • Configure Synchronization Connections An error has occurred while accessing the SQL Server database

    Hi,
    i am getting following error message
    Central Administration --> Synchronization Connections
    An error has occurred while accessing the SQL Server database or the SharePoint Server Search service.
    If this is the first time you have seen this message, try again later. If this problem persists, contact your administrator.
    Central Administration -->  Manage Profile Service: User Profile Service Application --> Manage User Properties
    Error
    An unexpected error has occurred.
    Troubleshoot issues with Microsoft SharePoint Foundation.
    Correlation ID: 3bce5a11-f2dc-4788
    Please tell how to fix it.
    iffi

    Event ID 5555 -> i have change the Timer jobs recycling time AM to PM
    for  User profile page not display  number of count in the page first check services , connection , 
    IISRESET /NOFORCE   /  timer services restart 
    Deepesh Yevle MCTS

  • MS Access querying SQL Server: How to configure Network ACL?

    I need to set up a highly restrictive ACL for access to a particular SQL server in our network.  This ACL will reside on our core switch at the "front door" of our network and permit access to the SQL server only using the ports that
    are necessary.  The purpose is to A) Try to keep unauthorized users from gaining access to the host server and B) Should someone somehow gain unauthorized access to the host server. keep them from being able to "hop off" to other PC's on
    the network. 
    The server will be accessed by clients using MS Access to query the SQL database and bring back reports.  A few admins are actually able to make minor changes to the database such as updating a user list or location list. In other words, both
    read and write access is needed to the SQL database.
    I know that the default SQL server port is 1433, but according to a Microsoft Support article I read, "client ports are assigned a random value between 1024 and 5000".
    I was really hoping I could just put something like "permit PC1 access to SQL Server on Port 1433" in my ACL, but after reading the MS Support article it sounds like I've got to allow almost 4,000 ports through?
    Could someone help demystify this for me so I can build the right ACL?

    The tool to use is SQL Server Configuration Management.
    But what you can configure is which port SQL Server listens to. Which port the client listens to is not controllable as far as I know. But that can of course be many, since a client can have many connections to SQL Server. (And the range is not
    restricted to 1024-5000. I connected over TCP locally, and I see this with netstat -a
      TCP    127.0.0.1:6621         NATSUMORI:ms-sql-s     ESTABLISHED
    Then again, I don't see why you would have to open any ports for the clients at all. I have never heard of this being a problem.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Migration from MS access to sql server

    Hi,
    I need to move e-manager db from a MS Access to a SQL server.
    I succeeded in moving all tables, relations and views but I run into problems when executing the view lTestCases_Requirement .
    I get a sql execution error due to a data type conversion error:
    "Error msg: Conversion failed when converting the nvchar value 'failed' to data type int." (complete error msg attached)
    The error is probably in the referred view vTestCase.
    Do yo have any tips on how to handle this,. If I use the SQL server with this error It won't work probably.
    How can I solve this issue? I really need to migrate to SQL server.
    /Jakob

    Hello LDAP,
    This doc here might help..It describes the procedure that needs to be followed in order to convert your current MS Access based e-Load database to a SQL Server based database.
    http://qazone.empirix.com/entry.jspa?externalID=44&categoryID=44
    (you will need to use your QAZone account to read it)
    -----Marina

  • Upsizing from Access to SQL Server - eek!

    Ok - I've built quite a few dynamic sites using DW and
    Access, but the site
    i'm currently working on requires Microsoft SQL Server for
    the database.
    The site is almost complete and is written in Classic ASP.
    Can anyone point me in the right direction, tutorials, crash
    course, etc to
    get me up to spped with the task?
    Would my ASP code need changing at all?
    Thanks in advance
    Andy

    Hi Joe
    Thanks for the help -
    Andy
    "Joe Makowiec" <[email protected]> wrote in
    message
    news:[email protected]..
    > On 19 Feb 2007 in macromedia.dreamweaver.appdev, Andy
    wrote:
    >
    >> Ok - I've built quite a few dynamic sites using DW
    and Access, but
    >> the site i'm currently working on requires Microsoft
    SQL Server for
    >> the database. The site is almost complete and is
    written in Classic
    >> ASP.
    >>
    >> Can anyone point me in the right direction,
    tutorials, crash course,
    >> etc to get me up to spped with the task?
    >> Would my ASP code need changing at all?
    >
    > As Far As I Know - the only place you'll run into a
    problem is that there
    > are a few differences in SQL between Access and SQL
    Server. There are a
    > number of sites with information:
    >
    >
    http://www.google.com/search?q=differences+access+sql+server
    >
    > The first result (at aspfaq.com) looks good.
    >
    > But you shouldn't have any problem with the ASP code. I
    think you'll
    > like the change from Access to SQL Server.
    >
    > --
    > Joe Makowiec
    >
    http://makowiec.net/
    > Email:
    http://makowiec.net/email.php

  • What is the best NLS config to be near the ACCESS or SQL Server characters set

    Hi all,
    I am working with an Oracle for Windows.
    I have serious problems with my actual characters set.
    What is the best NLS config to be near the ms-Access or SQL Server characters set behavior ?
    For exemple :
    I have a table with city names
    I want to find the nearest >= city name of a given criteria. so i do this SQL
    SELECT Nom FROM TLCommune WHERE Nom >= 'LIMOGES' ORDER BY Nom, Pays, Dept, Insee
    This SELECT give this result under SQL plus worksheet (same via VB and ADO)
    Why the cities from krosno to Limerick are listed regarding on the WHERE clause Nom >= 'LIMOGES' ?
    NOM
    krosno
    La Manche et la Mer d'Irlande
    Laesv
    Lancashire
    Landes
    Lappi (Lappland)
    Latviya
    Legnica
    Leicester and Rutland
    Leipzig
    Leningrad
    NOM
    Leon
    Lirida
    Leszno
    Liberec
    Libiria
    Libye
    Limburg
    Limburg (Limbourg)
    Limerick
    LIMOGES <--------------------------------------- the city in the nom >= 'LIMOGES' in the SQL statement
    LIMOGES-FOURCHES

    Hi,
    Try these steps:-
    * Open the GUI of Root bridge
    Go to Security/SSID Manager/create SSid/map it to the radio
    * Under Client Authentication setting
    Check the box Open authentication with no Addition ..
    * Then click Apply
    * Go to Ecryption Manager page
    Under Ecryption Modes
    Select Cipher ---TKIP
    Under Encryption Keys
    Select Encryption Key 2 ------Don't put any key ... Leave the box blank and key size be 128bit
    Then click Apply
    * Come back to SSID Manager page
    Under Client Authenticated Key Management ..
    Select Key Management:- Mandatory
    Check the box:- WPA
    Under WPA Pre-shared Key:- Type atleast 8 character key..
    Click Apply:-
    * Then we need to repeat the same settings on Other bridge except the station role will be non-root.
    Now to troubleshoot...
    * First make Bridge are able to talk to each when there is on security setup
    * Set a simple Pre-shared Key ... example 1234567890 on both bridge .. Bridge will not associate if key mismatch..
    Hope this will work for you.

  • How can I develope a native mobile cross platform app that can access an SQL server.

    I would do it in html5 as a web app but I also need to access an SQL server and upload data(text) pictures from the camera and
    geolocation data etc.
    I've developed many web based applications, but this is this first attempt to integrate native device functions AND interact with an SQL database.
    So it would have to be able to use form data  then add a photo and geolocation and send everything to the database.
    A site with examples and/or tutorials would be nice.
    To make things worse, I'd also have to be able to work offline and re-sync when networks connections allow.
    If a native app would be too complex, then I was thinking I might be able to develope an app that gathers data then
    passes the info on to a browser to connect with the database.
    But as much as possible I don't want to have to swing back and forth between a browser and an app.
    Pete

    Here is a page a I bookmarked a while back to use jQUERY to access a php scripts sitting on a server that can then interact with the database in the usual way. This means that you will be able to use DW to create the usual HTML CSS and jQuery to make an interactive app.
    I havn't yet tried this but a quick look over the script looks good. Make sure you use php that sanitizes input.
    http://stackoverflow.com/questions/8246380/adding-a-database-to-jquery-mobile-site
    Let me know how you go.

  • Is there any way of importing stuffs from Microsoft Access to SQL Server?

    I have quite a big store of information Microsoft Access DB, but now i am required to switch to SQL Server?
    Is there any way of importing to SQL Server, either by Java programming or manually?
    Thank you in advance.

    I like to give some tips on how to fulfil the requirement.. I haven't tried this. If you succeeded, it is well and good.
    1) Using Java:
    If you like to Java to import the data from MS Access to SQL Server, you have to write a JDBC Program in such a way that it has to retrieve the data from each MSAccess tables and store it in temperory java varaible.After writng into the temp. varaibles, the same thing will be written into SQL Server. The whole process is repeated for all the tables in MS Access.
    2) Manual Process:
    Try to get the data scripts from MS-Access for all the tables and Load the same into SQL Server
    I hope that Manual Process consumes less time compared in writing the codes for transformation..
    I hope that you got some idea on reading this. If you have any doubts, try to get back to me..

  • SQL Server with BIDS install

    Which version of SQL Server with BIDS is recommended for a starter? I keep on running in various problems when installing and uninstalling.

    SQL Server 2014 is the latest SQL version and from SQL 2012, BIDS is replaced with SSDT(sql server data tools). refer: https://msdn.microsoft.com/library/cc645993.aspx?f=255&MSPPError=-2147217396
    Express edition does not have this. but SQL 2014 'Express with advanced services' edition has it. i do not think  full functionality is available though. 
    if you only want BIDS, you can install SQL 2008R2 express with advanced services edition. google for the link
    this link is for SQL 2008 http://www.microsoft.com/en-us/download/details.aspx?id=1842
    if this is for learning purpose, i would recommend installing sql 2014 enterprise evaluation edition. that way you can get full exposure to SQL product suite
    Hope it Helps!!

  • SQL Server 2005 Update mechanism problem

    Hi Gurus,
          We're faced with one SQL Server 2005 update mechanism problem. Here is my problem:
          According to our requirement, an add_on interface program is designed to execute creation of production order by calling Bapi.
          There are 3 steps in this add_on program:
          Step 1: Create production order
          Step 2: Change the information of production.
          Step 3: Some other
          After the step 1 has finished immediately step 2 is called, Howerver the information which should have inserted into database table couldn't be found from database. (Maybe because the time between two steps is too short to finish inserting)
          In order to ensure the complete of the transaction, before the step 2 executed, the information in step 1 should have inserted into database.
           Is there any solution to solve this problem?
           I guess whether there is any parameter which control the time of writing buffer into database...
    Any advice is appreciated.
    Thanks & Best Regards,
    Derek Yang

    Hi
    I have the same problem, but that post didnt help me
    This is the error I have:
    My snapshot agent hangs.. waiting for a response from the server.. and timeouts.
    This only hapens for a publication that has a filter based on HOSTNAME()
    The other publications work fine
    Error messages:
    Message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
    Command Text: sp_MSsetup_partition_groups
    Parameters: @publication = XXXXXXX
    Stack: at Microsoft.SqlServer.Replication.AgentCore.ReMapSqlException(SqlException e, SqlCommand command)
    at Microsoft.SqlServer.Replication.AgentCore.AgentExecuteNonQuery(SqlCommand command, Int32 queryTimeout)
    at Microsoft.SqlServer.Replication.AgentCore.ExecuteDiscardResults(CommandSetupDelegate commandSetupDelegate, Int32 queryTimeout)
    at Microsoft.SqlServer.Replication.Snapshot.MergeSnapshotProvider.SetupPartitionGroups()
    at Microsoft.SqlServer.Replication.Snapshot.MergeSnapshotProvider.DoRegularMergeSnapshotPreparations()
    at Microsoft.SqlServer.Replication.Snapshot.MergeSnapshotProvider.DoPreArticleFilesGenerationProcessing()
    at Microsoft.SqlServer.Replication.Snapshot.SqlServerSnapshotProvider.GenerateSnapshot()
    at Microsoft.SqlServer.Replication.SnapshotGenerationAgent.InternalRun()
    at Microsoft.SqlServer.Replication.AgentCore.Run() (Source: MSSQLServer, Error number: -2)
    Get help: http://help/-2
    Server XXXXXXXXX, Level 11, State 0, Procedure , Line 0
    Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. (Source: MSSQLServer, Error number: -2)
    Get help: http://help/-2

Maybe you are looking for

  • Trying to get my head around how SUPs work

    Hi fellas, Completely new to SCCM (well, I've  had some training, but still quite green).  I had some general questions about Software Update Points and best practices. 1.  When creating a SUP, would it be wise to select all classifications for all n

  • Have a hp deskjet all in one k209A

    the scanner appears to scan but will not save to the mac... when i try to trouble shoot  system preferences printers and scanners opens in a different desk top to the hp scan app so i cant resolve the issue ...... is my problem with the hp product or

  • SAP AR

    HI Gurus, currently in my company, customers receiving a dunning letter often argue that they did not receive the initial AR invoice. The requirement for me is to see if there is a possibility of sending the customer invoice the same time that we are

  • BW Roles are not updated in BOBJ system

    Hi All, We have created additional roles in BW system. But these roles are not updated in BOBJ system(BI 4.0). I am not able to see these roles in SAP Authentication when we update the user option too. Any solution for this? Regards, Krishna.K

  • NO MARKER UPDATE

    hi all, what is the use of  NO MARKER UPDATE in collapse tab of incube manage for specially inventory infocubes.. plz explain me in detail.. thanks in advance pinky reddy