see this is the code that is written in c# in visual studio 2005........In visual studio w can connect sql(not mysql) with c# and can even see the sql table visually.........
can we do that similarly in java in netbeans7.0.....
how can i connect sql with java.......do i need to connect the driver externally like that we connect Microsoft Access by connecting the driver through Data Sources (ODBC) in administrator tools in control panel.............
what should be the relevant code for java (the code that is given below is the connection for sql in c#)
String sq1, sq2;
SqlCommand cmd;
SqlDataReader rd1;
SqlConnection con;
String nam, pas;
nam = nam.Text;
pas = pass.Text;
SqlConnection con;
password = pass.Text;
try
{
con = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Documents and Settings\nidhish\My Documents\Visual Studio 2008\Projects\project\project\data.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True");
con.Open();
sq1 = "select * from admin where uname='" + usertext.Text + "'";
cmd1 = new SqlCommand(sq1, con);
rd1 = cmd1.ExecuteReader();
if (rd1.Read())
{
name = rd1[0].ToString();
passd = rd1[1].ToString();
rd1.Close();
}
if (name == usertext.Text && passd == passtext.Text)
{
MessageBox.Show("Login Success ", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
mainpage pg=new mainpage();
pg.Show();
}
}
catch (Exception) { }