Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 12th, 2012, 06:21 AM
Registered User
Join Date: Aug 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts

Originally Posted by mairaj View Post
import java.sql.Connection;
import java.sql.DriverManager;

* @author mairaj
public class DB {
static Connection con =null;
public static Connection getCon(){
con =DriverManager.getConnection("jdbc:mysql:\\localho st:3306\test","root","root") ;
catch(Exception e){}
return con;


Hi, miraj

You can try this code below

Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase?","root","root");
Statement st=conn.createStatement();

// your code goes here...

//close try block

}catch(Exception e){

//3306 is default portnumber of mysql

//mydatabase is databasename in mysql

//root is username

//root is password

It will work 100%

Try it..

All the best..
Old May 14th, 2012, 12:57 AM
Registered User
Join Date: May 2012
Posts: 5
Thanks: 0
Thanked 2 Times in 2 Posts

Interesting discussion..... Agree with you..... It will be better and profitable for him.... Good thought...
Originally Posted by Old Pedant View Post
Forgot to ask what operating system you are using.

If you are using Windows, you might want to look at the steps given here:

and maybe read this:

If not Windows, then what?

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# and mySQL Connection naifwonder C# 5 March 8th, 2008 01:52 PM
making an mysql connection Zoe-Alyssa Dreamweaver (all versions) 0 May 19th, 2006 02:16 PM
java/jsp and MySQL harshika Java Databases 2 August 2nd, 2005 02:07 AM
use ODBCDataAdapter Connection MySQL kofallen Classic ASP Databases 2 April 19th, 2005 03:02 PM
Mysql connection catab C# 4 December 7th, 2003 11:25 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.