SQL Connection

Get help on programming - C++, Java, Delphi, etc.
Post Reply
bhangie
Registered User
Posts: 220
Joined: 12 Jul 2004, 02:00
Location: Port Elizabeth
Contact:

SQL Connection

Post by bhangie »

Hi

I am starting to learn java in particular creating web applications so i am a newbie @ this. Ok I need to create a connection to SQL Database in my
application, Using Netbeans 5 i downloaded the jdbc drivers installed and all is working fine, Problem comes when i need to create a connection in my app
Can someone plz post some code so i can see how it suppose to done. I did
get examples from the web.

Code: Select all

class DConnection {
           public static void main(String[] args) {
            try {
              DriverManager.registerDriver(
                 new com.microsoft.sqlserver.jdbc.SQLServerDriver());
                 //In this line i get Package not found
   
                 Connection connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://PIAPE","sa","*****");
The right way to do this?
thanks in advance
Moses
Registered User
Posts: 2545
Joined: 21 Jul 2004, 02:00
Location: Location:
Contact:

Post by Moses »

Have you added this:
import java.sql.*; ?
Law
Registered User
Posts: 1569
Joined: 12 Sep 2003, 02:00
Location: UND

Post by Law »

soz man if my pc wasnt broken i could give you the code.

I created a java program that connected to a sql db. i'll see if i can find nething.
Image

MAY THE CHEESE BE WITH YOU!
{PK} Law
Moses
Registered User
Posts: 2545
Joined: 21 Jul 2004, 02:00
Location: Location:
Contact:

Post by Moses »

public Main() {

try {

// Here we load the JDBC driver.

Class.forName("org.postgresql.Driver"); (whatever driver you need)

} catch (ClassNotFoundException e) {

System.out.println("Unable to load driver!");


}

try {

Con = DriverManager.getConnection("jdbc:microsoft:sqlserver://PIAPE","sa","*****");

} catch (SQLException se) {

System.out.println("SQL Exception: " + se.getMessage());

se.printStackTrace(System.out);

}
This is just code I wrote once... May help.
bhangie
Registered User
Posts: 220
Joined: 12 Jul 2004, 02:00
Location: Port Elizabeth
Contact:

Post by bhangie »

Hi

Thanks for the help :)
@Moses your code works thanks man.

I Only had to do this

Code: Select all

Connection Con = DriverManger.getConnection....
Otherwise it will say Symbol not found i assume meaning a Variable Connection has not been declared.

thanx allot
Scarlet_Spider
Moderator Emeritus
Posts: 1632
Joined: 14 May 2003, 02:00
Location: Durban

Post by Scarlet_Spider »

dont know if this will help but here it is none the less http://www.connectionstrings.com/
------
a nikonian from South Africa....
Nikonians
Post Reply