Whats the easiest way to establish a DB connection

T

Tom

Hello everyone,

Im looking for the simplest way anyone can thank of to establish a
connection my my mssql server 2000 through my jdbc. Im looking for a
bit of code that i can take and build a program ontop of.
My project for school is to make an address book that will store Name,
City, phone#, blah blah blah.
Iv tried on my own but i cant get the connection to go through so i
thought id start with the connection and build ontop of that.
If i know the connection works then i dont think ill have any problem
with the tables and the rest of the code.


My connection code used to look like this.
But i kept running into to many errors that i didnt have answers for.
If anyone has any other suggestions about how to go about doing this i
would greatly appreciate it.

private void connect() throws Exception
{
JOptionPane.showMessageDialog(null,"CloudScape Inside Connect");

try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Properties p = new Properties();
p.put("selectMethod","cursor");
p.put("tom","sa");
p.put("password","tom");
connection = DriverManager.getConnection
("jdbc:microsoft:sqlserver://TOMLAP2:1433",p);
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null, ex.toString());
}


try
{
connection.setAutoCommit( false );
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null, ex.toString());
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top