Results 1 to 3 of 3
- 06-11-2008, 09:49 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 85
- Rep Power
- 0
How to connect a Java program with MySQL database?
Hi all
this thread is for beginners like me..just want to share the code which i tried out..
import java.io.*;
import java.sql.*;
class Sample
{
public static void main(String ds[])
{
Connection con=null;
Statement st=null;
ResultSet rs=null;
String FirstName="";
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance ();
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/yourdatabasename?","root","password?");
st=con.createStatement() ;
rs=st.executeQuery("SELECT fieldname? FROM yourTablename?") ;
while(rs.next())
{
FirstName=rs.getString(1);
System.out.println(fieldname);
}
}
catch(Exception eer)
{
System.out.println(eer.toString());
}
}
}
if anything is wrong please correct me...
- 06-11-2008, 09:51 PM #2
Member
- Join Date
- Jun 2008
- Posts
- 85
- Rep Power
- 0
The "FirstName" in the code is my field name you can give yours..
- 06-12-2008, 07:09 AM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
Help with Java application to connect to a database
By coco in forum JDBCReplies: 3Last Post: 09-18-2008, 03:07 PM -
MySQL Database and Java
By shaggymac in forum Advanced JavaReplies: 1Last Post: 05-01-2008, 09:01 PM -
Java program that transfers stock prices to MySQL database
By naipulb in forum New To JavaReplies: 2Last Post: 04-17-2008, 05:02 PM -
Connect applet with mysql
By baltimore in forum Java AppletsReplies: 1Last Post: 08-07-2007, 06:39 AM -
Connect applet with mysql
By Felissa in forum Java AppletsReplies: 3Last Post: 07-05-2007, 06:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks