Solved

Java prepared Document connection

Posted on 2013-05-22
13
260 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
oracle query help 18 78
Problem to start Neon 20 54
Modify a small python script 19 54
Birthdays 3 21
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

746 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