Connecting VB 2008 Express to MySQL

You need:

I will assume that you have you have installed software needed.

This will be your database schema


Then create a Windows Application Project in Visual Basic 2008 Express Edition and create a Windows Form similar to this..


Add the necessary Reference for MySQL Connection


Then choose the MySQL.Data


After adding reference, you will now be able to use the imports statement for the mysql controls/objects

This is the source code for the Windows Form

Imports MySql.Data.MySqlClient

Public Class Form1
Dim conn As MySqlConnection
Dim reader As MySqlDataReader
Dim command As MySqlCommand
Dim adapter As MySqlDataAdapter
Dim dt As DataTable

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub fetchData()
command = New MySqlCommand
dt = New DataTable
adapter = New MySqlDataAdapter

If (conn.State = ConnectionState.Closed) Then
End If

command.Connection = conn
command.CommandText = “select * from student”

adapter.SelectCommand = command

reader = command.ExecuteReader


DataGridView1.DataSource = dt

Catch ex As MySqlException
MessageBox.Show(“Error1: ” & ex.Message)
End Try

End Sub

Private Sub setConnection()
conn = New MySqlConnection
conn.ConnectionString = “Data Source=localhost;Database=tesda;User ID=root;Password=admin”
Catch ex As MySqlException
MessageBox.Show(“Error1: ” & ex.Message)
End Try
End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End Sub

Private Sub btnFetch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFetch.Click
MessageBox.Show(“Connecting to mysql!”)
End Sub
End Class

Here is the output


* due to the limitation of the display of the code, if you copy and paste this, your program might not work, because VB can read program codes, line by line. If you happen to split a statement to two or more lines, use the “underscore character” _ at the end of the statement.

* What is important here is the process of the connection and retrieval of data and displaying it to datagridview object

Installing Java and Tomcat 5.5 on Ubuntu Jaunty

If you want to try JSP with Tomcat then follow the steps:

1. Go to Applications -> Accessories – > Terminal

sudo apt-get install sun-java5-sdk tomcat5.5 tomcat5.5-admin tomcat5.5-webapps

2. After successfully installing all of the above packages, apt will prompt you for an error message. This is because of the java 5 documentation. Just follow the link that will be prompted by apt and download the files to /tmp. Then execute

apt-get install

3. Your web root will be at /usr/share/tomcat5.5-webapps/ROOT. This is where you will put your web applications or pages.

4. By default, tomcat runs on port 8180. If you want to change it to 8080 or just 80, edit the server.xml

pico /etc/tomcat5.5/server.xml

5. Search for this

<Connector port=”8180″ maxHttpHeaderSize=”8192″
maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″
enableLookups=”false” redirectPort=”8443″ acceptCount=”100″
connectionTimeout=”20000″ disableUploadTimeout=”true” />

and change 8180 to 8080 or if you want just 80.

6. Restart your tomcat

sudo /etc/init.d/tomcat5.5 restart

7. Open a browser and type,


if you choose 8080 on server.xml, and


if you choose 80 on server.xml