Solved

Java prepared Document connection

Posted on 2013-05-22
13
268 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 17
How do I remove an object from a 3 40
Query Syntax 17 42
servlet and mdb, jms error 1 30
This is an explanation of a simple data model to help parse a JSON feed
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

809 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