Results 1 to 15 of 15
Thread: Connect to SQl
- 06-30-2012, 02:29 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 14
- Rep Power
- 0
-
Re: Connect to SQl
This is not a very good question for a forum since surely Google will find you sample code, and then if you have any problems understanding the concepts a better question for this site would be to ask about your points of confusion or about any errors in your code attempts.
- 06-30-2012, 03:08 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 14
- Rep Power
- 0
Re: Connect to SQl
thanks for your answer
i try this code :
import java.sql.*;
public class ConnectURL {
public static void main(String[] args)
{
DB db = new DB();
db.dbConnect("jdbc:sqlserver://localhost:1433/test", "sa", "123" );
}
}
class DB{
public void dbConnect( String db_connect_string,
String db_userid,
String db_password)
{
try{
Class.forName( "com.microsoft.sqlserver.jdbc.SQLServerDriver" );
Connection conn = DriverManager.getConnection(
db_connect_string,
db_userid,
db_password);
System.out.println( "connected" );
}
catch( Exception e ){
e.printStackTrace();
}
}
};
but i meet error
please help me
- 06-30-2012, 03:24 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
- 06-30-2012, 03:55 PM #5
Member
- Join Date
- Jun 2012
- Posts
- 14
- Rep Power
- 0
Re: Connect to SQl
i have 2 question :
do my code is correct
and
i get this error :
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at DB.dbConnect(ConnectURL.java:18)
at ConnectURL.main(ConnectURL.java:9)
- 06-30-2012, 04:03 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
- 06-30-2012, 05:27 PM #7
Member
- Join Date
- Jun 2012
- Posts
- 14
- Rep Power
- 0
Re: Connect to SQl
thanks for your answer
please if possible show me how to connect to sql and fetch records
thanks
- 06-30-2012, 05:31 PM #8
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: Connect to SQl
Step 1, see post 6. Step 2: get the driver to your database. Step 3: add the driver to your classpath when your run the program. Step 4: verify the correct name of your driver. Steps 2, 3, and 4 can be greatly aided by the use of your favorite web search engine.
- 06-30-2012, 06:25 PM #9
Member
- Join Date
- Jun 2012
- Posts
- 14
- Rep Power
- 0
Re: Connect to SQl
thanks for your answer
i'm a .Net programmer
and i'm a new java programmer
if possible show me with cod
- 06-30-2012, 08:32 PM #10
Re: Connect to SQl
No. This is a forum, not a free coding service. As already said, there are tons of code samples to be found on the internet.
Also go through the following:
Forum Rules
Guide For New Members
BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 06-30-2012, 09:49 PM #11
Member
- Join Date
- Jun 2012
- Posts
- 14
- Rep Power
- 0
Re: Connect to SQl
i try this code :
String driverName = "com.sql.jdbc.Driver";
try
{
Class.forName(driverName);
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
and meet this error :
com.sql.jdbc.Driver
please help me
- 06-30-2012, 10:03 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Re: Connect to SQl
When people rob a bank they get a penalty; when banks rob people they get a bonus.
-
Re: Connect to SQl
I'm guessing that he's just trying to use with random code downloaded from the internet, that he doesn't yet have a database per se.
- 07-01-2012, 06:10 AM #14
- 07-02-2012, 11:17 AM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Connect to SQl
Microsoft's MSDN site has plenty of examples of connecting to SQLServer using JDBC, including what you need to do to get it to work.
In fact the first few links on a decent web search are all MSDN articles on it.
As a .NET programmer I'm sure you are aware of MSDN, so why you have chosen to come here first is slightly bizarre to say the least.Please do not ask for code as refusal often offends.
Similar Threads
-
Connect to wap
By HoangNgoc in forum CLDC and MIDPReplies: 2Last Post: 12-23-2010, 09:13 AM -
connect through usb
By taufiqbzz in forum NetworkingReplies: 0Last Post: 11-01-2010, 11:04 PM -
Connect 4
By pansylea in forum New To JavaReplies: 0Last Post: 12-11-2009, 03:36 PM -
how to connect with my GUI
By doha786 in forum New To JavaReplies: 2Last Post: 04-01-2009, 04:59 PM -
how connect
By herfnai in forum JDBCReplies: 1Last Post: 08-18-2008, 06:34 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks