• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

mysql..connectivity

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im very new to j2ee and mysql... i wanna entire connectivity coding..can please... ???
 
Marshal
Posts: 64642
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Aboo saimon,

Welcome to Javaranch,

Just a suggestion : its better to ask concept instead of coding..
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Posts: 64642
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 64642
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the mistake have moved it to new link as below.
Mysql COnnection fails
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!