Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

connection between JAVA & SQL SERVER

connection

  • This topic is locked This topic is locked
5 replies to this topic

#1 mkcit

mkcit

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 24 March 2007 - 01:55 PM

Please members , i need to help me ..

now i'm establishing my graduate project, and i'm useing java programming language,and sql server to implement the application, but i face problem, that i don't know how i can connect java with sql server.

so i hope from you to help me please, and if possible explain that step by step, and support that by simple pictures, becuase these steps is very necessary for me.
note : i download JDBC driver from microsoft web site for connection, and attempt by simple tests to make connection but i failed.

THANKS FOREVER
  • 0

#2 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 25 March 2007 - 12:35 AM

This is the code for connecting to a mysql server that I made for another post

package net.codecall.forums.general;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MySqlConnect {

	public static void main(String args[]) {
		Connection con = null;
		String dbname = "";
		String dbuname = "";
		String dbpassword = "";

		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			con = DriverManager.getConnection("jdbc:mysql:///" + dbname, dbuname, dbpassword);

			if(!con.isClosed()){
				System.out.println("Successfully connected to " + dbname);
			}
		} catch(Exception e) {
			System.err.println("Exception: " + e.getMessage());
		} finally {
			try {
				if(con != null){
					con.close();
				}
			} catch(SQLException e) {}
		}
	}
}

  • 0

#3 mkcit

mkcit

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 25 March 2007 - 02:24 AM

Thanks Mr Sidewinder for code, but in fact i want the way to connect by sql server.
  • 0

#4 SNK111

SNK111

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 14 June 2010 - 07:14 AM

Check this article HOW TO: SQL in JAVA for details on how to connect to SQL Server database from C#.NET database applications as well as Java database applications. It also describes how to pass embedded SQL queries (SELECT, INSERT, UPDATE, DELETE), calling stored procedures, pass parameters etc.

Shahriar Nour Khondokar
  • 0

#5 GMVResources

GMVResources

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 71 posts

Posted 14 June 2010 - 01:23 PM

Maybe if it still doesn't work use a different server
  • 0

#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 14 June 2010 - 02:17 PM

This is a three year old thread!
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download