question about MySQL and java connectivity
Hi
I am kind of new to Database but I am quite familiar with java, I want to do the following:
I want to have my PC running a java application and that application should send data let us say "current time" to a MySQL database on a website, I have read about Java and MySQL but till now I didnot know what should I do on my CPANEL (i think some settings must be set correctly on the web site to enable it to receive the data), can you recommend a good books or tutorials regarding my issue.
I have found this very basic code, and I think it serves me well but what to do with the CPANEL and where to write the user name and the password of the database:
Code:
1 import java.sql.*;
2
3 public class SimpleJdbc {
4 public static void main(String[] args)
5 throws SQLException, ClassNotFoundException {
6 // Load the JDBC driver
7 Class.forName("com.mysql.jdbc.Driver");
8 System.out.println("Driver loaded");
9
10 // Establish a connection
11 Connection connection = DriverManager.getConnection
12 ("jdbc:mysql://mywebsite/test");
13 System.out.println("Database connected");
14
15 // Create a statement
16 Statement statement = connection.createStatement();
17
18 // Execute a statement
19 ResultSet resultSet = statement.executeQuery
20 ("select firstName, mi, lastName from Student where lastName "
21 + " = 'Smith'");
22
23 // Iterate through the result and print the student names
24 while (resultSet.next())
25 System.out.println(resultSet.getString(1) + "\t" +
26 resultSet.getString(2) + "\t" + resultSet.getString(3));
27
28 // Close the connection
29 connection.close();
30 }
31 }
Best Regards.
Anderson.