Tuesday, March 22, 2011

MYSQL Database Connection String in different programming language

VB.NET
Private Sub Form1_Load(ByVal sender As ObjectByVal e AsSystem.EventArgs)
        Dim connectionString As String = "Driver=MySQL}; SERVER=localhost; DATABASE=NorthwindMySQL;"
        Dim conn As New OdbcConnection(connectionString)
        conn.Open()
        Dim da As New OdbcDataAdapter("", conn)
        Dim ds As New DataSet("Cust")
        da.Fill(ds, "TABLENAME")
        dataGrid1.DataSource = ds.DefaultViewManager
        conn.Close()
End Sub


JAVA
public static void main(String args[]) {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:///test","root", "secret");  
  if(!con.isClosed())
System.out.println("Successfully connected to MySQL server using TCP/IP...");
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage())
  } finally {
try {
if(con != null) 
con.close();
} catch(SQLException e) {}
}
}


PHP
$dbhost = 'localhost';       
$dbuser = 'root';       
$dbpass = 'password';
      $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
      $dbname = 'petstore';       

mysql_select_db($dbname); 

2 comments:

Related Posts Plugin for WordPress, Blogger...

Blog List