File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes mysql..connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "mysql..connectivity" Watch "mysql..connectivity" New topic
Author

mysql..connectivity

Aboo saimon
Greenhorn

Joined: Aug 12, 2008
Posts: 5
im very new to j2ee and mysql... i wanna entire connectivity coding..can please... ???
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39755
    
  28
Welcome to JavaRanch

"I want doesn't get" is what we were told as little children.

Please read some of our FAQs. Look at the MySQL handbook and the Java� Tutorials.
[ August 13, 2008: Message edited by: Campbell Ritchie ]
aleem khan
Ranch Hand

Joined: Aug 07, 2008
Posts: 94
String url = "jdbc:mysql://localhost:3309/";
String db = "search";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement stmt = con.createStatement();
String table = "CREATE TABLE Employee(SSN integer,Name VARCHAR(40),DOB VARCHAR(20),Address VARCHAR(100))";
stmt.executeUpdate(table);
}catch (SQLException s){
}

The above code is tested code, it should work. Here db="search" is your database name. Let me know if you are successful


SCJP(1.4), SCWCD, Oracle 9i SQL certified, Oracle PLSQL Developer Certified Associate
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

hi Aboo saimon,

Welcome to Javaranch,

Just a suggestion : its better to ask concept instead of coding..


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by lavani aleem khan:
String url = "jdbc:mysql://localhost:3309/";
String db = "search";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
Class.forName(driver);
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement stmt = con.createStatement();
String table = "CREATE TABLE Employee(SSN integer,Name VARCHAR(40),DOB VARCHAR(20),Address VARCHAR(100))";
stmt.executeUpdate(table);
}catch (SQLException s){
}

The above code is tested code, it should work. Here db="search" is your database name. Let me know if you are successful


If I were you, I would have been showed some respect to the Campbell's post, and never post the code. Anyways, we are here to learn. Have a good time.

Cheers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39755
    
  28
Originally posted by Adeel Ansari:


If I were you, I would have been showed some respect to the Campbell's post, and never post the code. Anyways, we are here to learn. Have a good time.

Cheers.
Actually, all the code was in my post . . . but you had to click the links to find it. And there is a major error in the code quoted, viz the empty catch block.

You are right, however; following the links and copying the code from the handbook is a better way to learn. But in real life, you don't actually need to learn the code if you can remember which page of the handbook it is on.
[ August 14, 2008: Message edited by: Campbell Ritchie ]
Adithya NN
Greenhorn

Joined: May 14, 2008
Posts: 6
Hi,
I am using the following piece of code for establishing the connectivity

However i am getting the following exception when i run the program


Could any body help me and tell me what i am doing wrong ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39755
    
  28
Welcome to JavaRanch Adithya Neurons.

Please don't post something unrelated to the original thread; this is called hi-jacking and may lose the original poster their topic.

It would have been better to start a new thread.
Please get the SQLException to print out its error code and SQL state and go to the MySQL handbook and search for those error types and their explanation.
Please find out which query it is not working, go to the tables queried and see what sort of characters you are using there. What sort of charset are you using in your database? That will give a bit more information for a start.
[ August 14, 2008: Message edited by: Campbell Ritchie ]
Adithya NN
Greenhorn

Joined: May 14, 2008
Posts: 6
Sorry for the mistake have moved it to new link as below.
Mysql COnnection fails
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mysql..connectivity