Solved

Java prepared Document connection

Posted on 2013-05-22
13
266 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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