Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Java prepared Document connection

Posted on 2013-05-22
13
Medium Priority
?
273 Views
Last Modified: 2013-05-24
How would I change the code below to connect to a SQL Server database on my intranet?

  public static Connection getConnection() throws Exception {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:databaseName";
    String username = "name";
    String password = "password";
    Class.forName(driver);
    Connection conn = DriverManager.getConnection(url, username, password);
    return conn;
  }

Open in new window

0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39188550
0
 

Author Comment

by:lrbrister
ID: 39188672
CEHJ...
I'm struggling here.
I've tried to implement the linked example like this
	  public static Connection getConnection() throws Exception {
		    String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		    String url = "jdbc:sqlserver://myserver;databaseName=[Assignment control system_be]";
		    String username = "WebServices";
		    String password = "password";
		    Class.forName(driver);
		    Connection conn = DriverManager.getConnection(url, username, password);
		    return conn;
		  }

Open in new window


But its saying "cannot find....and erroring on and on..."  on the com.microsoft.sqlserver.jdbc.SQLServerDriver line

s1
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39188843
The sql server driver jar is not in your classpath
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lrbrister
ID: 39188877
CEHJ,
  Ok...I recognize the vowels and consonets.

I copied my jar file into the
C:\Program Files (x86)\Java\jre7\bin>  directory.

I downloaded the C:\Program Files (x86)\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu files.

What do I copy into the Java directory?
sqljdbc.jar or sqljdbc4.jar?
And what else needs to be done?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39188942
I downloaded the C:\Program Files (x86)\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu files.

Open in new window

So that's where the jars are? You can tell Microsoft people don't work at the command line much can't you? ;)

Can you please paste in your previous command line (don't attach an image) and i'll give you the correct command?
0
 

Author Comment

by:lrbrister
ID: 39188964
CEHJ

Well...not in about 20 years anyway.
Went from HP2000 Data General
to ColdFusion and Microsoft for a while
:-)


Anyway...my command
From this directory      C:\Program Files (x86)\Java\jre7\bin

This is my command
java -cp m5.jar org.m5.sdk.hostedconnect.v1.ScreenPop  https://myurl.com 9999999999 12345
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39188980
Well...not in about 20 years anyway.
Went from HP2000 Data General
to ColdFusion and Microsoft for a while

I'm not talking about you - i'm talking about them ;) No Unix pro would ever create a directory with such a ludicrous name

Try

java -cp 'C:\Program Files (x86)\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu files\*;m5.jar' org.m5.sdk.hostedconnect.v1.ScreenPop 

Open in new window

(assuming the jars are in that 'enu files' directory)
0
 

Author Comment

by:lrbrister
ID: 39189198
CEHJ
I made sure that I copied in the M5 jar file and its supporting files

I executed your code from this directory
C:\Program Files (x86)\Java\jre7\bin>

But I'm getting Error: Could not find or load main class Files

ss
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 39189279
Well you shouldn't copy other jars into there, but since you have, you should be able to do

java -cp 'C:\Program Files (x86)\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\*' org.m5.sdk.hostedconnect.v1.ScreenPop 

Open in new window

                                           
You need to paste that into the command line since, even though it was wrong (i misread there being 'files' on the end of one path) i don't think you executed exactly what i gave you
0
 

Author Closing Comment

by:lrbrister
ID: 39194147
CEHJ,
 Sorry for the late getback.
Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39194512
:)
0
 

Author Comment

by:lrbrister
ID: 39194524
CEHJ,
 By the way...I'm fairly competent in VB.Net but was floundering my way through Java
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39194638
You'll get used to it ;)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

705 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