Solved

Java prepared Document connection

Posted on 2013-05-22
13
264 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This is about my first experience with programming Arduino.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now