Home Answers Viewqa JDBC how to connect mysql with JDBC

 
 


uma
how to connect mysql with JDBC
2 Answer(s)      4 years and 9 months ago
Posted in : JDBC

View Answers

September 12, 2008 at 11:03 AM


package library.code;

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

/**
* @author SIRI Technologies
*/
public class DbConnection {

Connection connection = null;
Connection connectDB() {


try {
Class.forName("com.mysql.jdbc.Driver");
}catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/YourDatabaseName e.g employee", "root", "");
}catch (Exception e) {
e.printStackTrace();
}
return connection;
}
public static void main(String args[]) {
DbConnection db =new DbConnection();
db.connectDB();
}
}

Thanks
Rajanikant

September 12, 2008 at 11:21 AM


Hi friend,


To mysql connect using JDBC .


Create a dabase "jdbctutorial"

Create a Table "employee"


To connect with database

Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);


Example to Display record from database using Jdbc:

import java.sql.*;

public class GetAllRows{
public static void main(String[] args) {
System.out.println("Getting All Rows from a table!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM employee");
System.out.println("Emp_code: " + "\t" + "Emp_name: ");
while (res.next()) {
int i = res.getInt("Emp_code");
String s = res.getString("Emp_name");
System.out.println(i + "\t\t" + s);
}
con.close();
}
catch (SQLException s){
System.out.println("SQL code does not execute.");
}
}
catch (Exception e){
e.printStackTrace();
}

For read in details JdBC to visit....

http://www.roseindia.net/jdbc/jdbc.shtml

Thanks









Related Pages:
how to connect mysql with JDBC - JDBC
how to connect mysql with JDBC  I have created three tables in the database MYsql, i have to connect them now using JDBC, can u please suggest me...(); } } Thanks Rajanikant  Hi friend, To mysql connect using JDBC
how to connect mysql from gui?
how to connect mysql from gui?  i am unable to connet to mysql server from my projet that is gui for mysql...can anyone help me in this...its urgent...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql
could not connect to the server - JDBC
could not connect to the server  Hii sir, I am working with a JBDC program now. Now i am trying to host it. when i am trying to connect to the remote MySqL server, i got an exception like
Mysql connect
Mysql connect  i can have a mysql database file and mysql-connector-net .but i have not mysql database. how to connect vb.net thsis database.(C:\Documents and Settings\Admin\My Documents\VB.NET\Stock delna\STC.sql ). plz help me
Connect JSP with mysql
; This query creates database 'usermaster' in Mysql. Connect JSP with mysql : Now in the following jsp code, you will see how to connect... Connect JSP with mysql   
How to connect mysql with jsp
How to connect mysql with jsp  how to connect jsp with mysql while using apache tomcat
not able to connect to mysql using.. jdbc
not able to connect to mysql using.. jdbc   i am not able to connect to mysql using jdbc .. is there any classpath that i need to set..because i am using mysql-connector-java jar file..to connect to mysql.. Pls provide the steps
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
how can i create a mysql database to connect to this code - JDBC
how can i create a mysql database to connect to this code  i need..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register
how to connect jsp to mysql - Java Beginners
how to connect jsp to mysql  I m new in Mysql and JSP i m... me hw to conncet jsp with mysql this is connection file package connect... =DriverManager.getConnection("jdbc:mysql://localhost:3306/rsdatabase","root
how to connect swings with jdbc... - Java Beginners
how to connect swings with jdbc...  Hi friends, Is it possible..."); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root
how to connect j2me program with mysql using servlet?
how to connect j2me program with mysql using servlet?  my program... = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+db,username,password...(); String userid=connect(user.toLowerCase().trim(), pwd.toLowerCase().trim
how to connect jdbc
how to connect jdbc  package com.tcs.ilp.Try.Controller; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import
Connect JSP with mysql
you how to connect to MySQL database from your JSP code. First, you need... Connect JSP with mysql   ... database in my sql command prompt) 2. Connect JSP with mysql
How to connect to MySql Database from Servlet?
; font-weight: bold; } How to connect to MySql Database from Servlet... will show you how to connect to MySQL database and perform select operation. You will learn the JDBC steps necessary to connect to the MySQL Database and execute
mysql_connect arguments
mysql_connect arguments   How many arguments a mysql_connection function required to connect to the database?   ?mysql_connect? function... And if the given arguments are correct it will connect to the database and print
cannot connect to database - JDBC
cannot connect to database  Iam using eclipse in my system ,when connecting the database mysql version 5.0 to the eclipse iam getting an error as ""Creating connection to mysql has encountered a problem.Could not connect to mysql
can't connect to MySQL Server(10060) - JDBC
can't connect to MySQL Server(10060)  Hii Sir, I am working... MySQL front end. Can we connect to the MySQL server using the I.P address... write as the subject. Can we connect thorugh a MySQL Frontend. Kindly
connect jdbc to an Excel spreadsheet
connect jdbc to an Excel spreadsheet  hello, How can I connect to an Excel spreadsheet file using jdbc?   Hello Friend, Follow..."); Connection conn = DriverManager.getConnection("jdbc:odbc:excel
Use JDBC to connect Microsoft Access
Use JDBC to connect Microsoft Access  How to use JDBC to connect Microsoft Access
how to connect two swing frames
how to connect two swing frames  how to connect two swing frames...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st
how to connect to database in php using mysql
how to connect to database in php using mysql  how to connect to database in php using mysql
How to connect with database
How to connect with database  jdbc connection
how to connect xlsx(2007 excel) - JDBC
how to connect xlsx(2007 excel)  i am not able connect to office 2007 excel file from jdbc
install mysql - JDBC
install mysql  i want to connect with mysql database.can i install mysql on local system please send me link how download mysql   Hi... understand how to Download and Install MySQL. Please visit the following link : http
how to connect mySql drivers into eclipse(configuration)?
how to connect mySql drivers into eclipse(configuration)?  how to connect mySql drivers into eclipse(configuration)? I need the configuration in eclipse. what do i have to download from mySql and just downloading is enough or do
what is ment by jdbc and how to connect with database?
what is ment by jdbc and how to connect with database?  i want answer for this question
Connecting to remote mysql server using jdbc.
Connecting to remote mysql server using jdbc.  How to Connect to remote mysql server using jdbc
JDBC
"); Connection connect = DriverManager.getConnection("jdbc:mysql://localhost...; How to retrieve the value from database into dropdown list using JDBC &...").newInstance(); String connectionURL = "jdbc:mysql://localhost:3306/test";; Connection
Connecting to MySQL
(); bds.setDriverClassName("com.mysql.jdbc.Driver"); bds.setUrl("jdbc:mysql...(""); try { System.out.println("Trying to connect!!"...-dbcp.jar, commons-pool.jar, j2ee.jar and mysql-connector-java-5.1.7-bin.jar
jdbc - JDBC
management so i need how i can connect the pgm to database by using jdbc... at http://www.roseindia.net/jdbc/jdbc-mysql/ Thanks   Hi, You can use following code to connect to Database with the help of JDBC API
Using javabeans to connect mySQL database on a jsp page - JSP-Interview Questions
Using javabeans to connect mySQL database on a jsp page  Hi, Am doing my project and I don't know how to connect a jsp page to a mySQl database...; Connecting a JSP page to MYSQL Database using JavaBean File Name: beancode.java
jdbc - JDBC
[] args) { System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306/"; String dbName...jdbc  How to do connectivity with java?  Hi friend
mysql jdbc connectivity
mysql jdbc connectivity  i want to connect retrieve data from mysql using jdbc
jdbc mysql - JDBC
=DriverManager.getConnection("jdbc:mysql://localhost:3306/ram","root","root...jdbc mysql  import java.sql.*; public class AllTableName... ** java.net.SocketException MESSAGE: java.net.SocketException: Invalid argument: connect STACKTRACE
jdbc - JDBC
in a database System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306/"; String dbName...jdbc  how to get tablecount in jdbc  hai frnd... wat do u
Using Network Address To Connect to a Database
.style1 { text-align: center; } How To Use Network Address To Connect... to connect a MySql database with your application over a network then you must load.... The syntax for MySql conection Url is as jdbc:mysql://[host][,failoverhost
How can I connect my database to my application ?
How can I connect my database to my application ?  How can I connect my database to my application?   Hi, You can use JDBC API to connect...( "jdbc:mysql://localhost:3306/test", "root", "root"); Statement statement
pls provide steps to connect mysql in flex - XML
pls provide steps to connect mysql in flex   hi ,PLS SUGGEST ME I HAVE NO IDEA WHERE TO PLACE THE FUNCTIONS.PHP CODE.I HAVE WAMP SERVER .CAN I PASTE THE FUNCTIONS.PHP THERE .OR ANY OTHERWAY .HOW FLEX CONNECT WITH WAMP .IF SO PLS
problem connect jsp and mysql - JSP-Servlet
: 15: <% 16: String url="jdbc:mysql://localhost/test"; 17: con...problem connect jsp and mysql  hello, im getting an error while connecting jsp and mysql. I have downloaded the driver mysql-connector
connect netbeans with oracle
connect netbeans with oracle  how to connect netbeans with oracle.../jsf/visual-jsf.shtml Here you will find the steps to connect netbeans with mysql database. Thanks
Connect database in Access to Netbean?
Connect database in Access to Netbean?  how to connect database in micrsoft access to Netbean?i know it can be connected by using JDBC-ODBC bridge, can i know the steps in connecting the database? Is there any source code
Mysql & java - JDBC
to connect to mysql 5.1 using java. But it shows error about: Class.forName...) { System.out.println("MySQL Connect Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306/"; String dbName
JDBC
JDBC  How to connect JAVA Servlet with the database
Prepared statement JDBC MYSQL
Prepared statement JDBC MYSQL  How to create a prepared statement in JDBC using MYSQL? Actually, I am looking for an example of prepared statement.   Selecting records using prepared statement in JDBC
jdbc
how to connect JSP page to database - JDBC  how to connect JSP page to database ?give program
jdbc connectivity to mysql tutorial
jdbc connectivity to mysql tutorial  here is complete jdbc connectivity to mysql tutorial for newbies. Person who don't even know how to install mysql and don't know about which driver to use can do with ease
j2ee - JDBC
and then use JDBC api to connect to MySQL database. Following two tutorials shows how...j2ee  how to connect jsp to mysql   Hi, Thanks for asking question. I will tell you how you can connection to MySQL from JSP page
MySQL connectivity - JDBC
MySQL connectivity  hi all, i am not able to connect Mysql to java ..as i connect it ..i am getting the error ..saying classNotFoundException... to "com.mysql.jdbc.Driver" class not found In the lib folder "mysql-connector-java-5.0.6-bin.jar
pls provide steps to connect mysql database in flex - XML
pls provide steps to connect mysql database in flex  hi,i am new to flex and doing project. i have doubt in how to connect MYSQL database in flex .pls provide the steps . i would be really thankful 2 u. i am loooking

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.