Results 1 to 13 of 13
- 07-12-2010, 11:00 PM #1
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
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:
Java 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.Last edited by mr_anderson; 07-12-2010 at 11:10 PM.
- 07-13-2010, 02:21 PM #2
- 07-13-2010, 02:28 PM #3
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Thank you for your reply, the question now is what to do in the CPANEL ?
i.e what settings should be made ?
Regards.
Anderson
- 07-14-2010, 09:01 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Not that I've ever actually done this for MySQL, but I think you need to tell it to allow connections from the IP address of your client machine. There should be stuff in the MySQL documentation for that, which is online...
- 07-14-2010, 01:34 PM #5
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
But I want to make access to the Database from any pc, thatz why I am writing my program.
Thank you for your reply.
Regards.
Anderson.
- 07-15-2010, 10:26 AM #6
- 07-15-2010, 11:19 AM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
He's talking about the CPanel of the website his MySQL resides on.
He needs to have the MySQL set up to accept connections from outside the web server.
Which does remind me that a lot of hosts don't actually allow this.
- 07-15-2010, 02:12 PM #8
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
I guess that is what is happening with me because I am getting this error Message from the server when I try to log in:
jdbc:mysql://websiteurl.com:3306/
java.sql.SQLException: Access denied for user 'myTESTusername'@'d58-110-200-85.mas9.nsw.optusnet.com.au' (using password: YES).
when I try the same code on my local machine it works just fine but when I try it on my website i get this response.
Thank you guys you were really helpful, I think I found the it under the name "Remote Database Access Hosts", in which I have to specify the IP of the remote machine which will be granted to access the Database, since I want to enable my software to connect to the DB from any PC, I will set address of the remote machine to wildcard:
%.%.%.%
I will try it and inform you.
Regards.
Anderson.
- 07-15-2010, 02:37 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Isn't '*' the wildcard?
- 07-15-2010, 11:02 PM #10
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Not as I can see in my Cpanel :D, he denotes it with % instead of *
Regards.
Anderson.
- 07-16-2010, 09:00 AM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Oh right.
I always have to look these things up.
- 07-16-2010, 05:04 PM #12
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
at the begining i was getting this code (before I made any configuration in the cpanel):
jdbc:mysql://websiteurl.com:3306/
java.sql.SQLException: Access denied for user 'myTESTusername'@'mywebsite' (using password: YES).
After I set the address of the "Remote Database Access Hosts" in my cpanel to wild card I got this message:
java.sql.SQLException: Unknown initial character set index '192' received from server. Initial client character set can be forced via the 'characterEncoding' property.
at com.mysql.jdbc.Connection.configureClientCharacter Set(Connection.java:2633)
at com.mysql.jdbc.Connection.initializePropsFromServe r(Connection.java:3239)
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:1803)
at com.mysql.jdbc.Connection.<init>(Connection.java:4 50)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:411)
at java.sql.DriverManager.getConnection(DriverManager .java:582)
at java.sql.DriverManager.getConnection(DriverManager .java:207)
at javaapplication4.Connect.main(Connect.java:29)
Regards.
Anderson.Last edited by mr_anderson; 07-16-2010 at 05:07 PM.
- 07-21-2010, 04:30 AM #13
Member
- Join Date
- May 2010
- Location
- Florida
- Posts
- 68
- Rep Power
- 0
Similar Threads
-
Connectivity issue-MySQL and Java
By Pragya in forum JDBCReplies: 9Last Post: 01-27-2010, 05:28 PM -
Connectivity to jbpm through java
By subrahmanyam.adapa in forum Reviews / AdvertisingReplies: 0Last Post: 12-31-2009, 06:33 AM -
MySQL connectivity (hours wasted)
By ribbs2521 in forum New To JavaReplies: 13Last Post: 10-21-2009, 07:18 AM -
Java Database Connectivity
By Java Tutorial in forum Java TutorialReplies: 2Last Post: 02-08-2009, 02:15 AM -
java with database connectivity
By thamizhisai in forum New To JavaReplies: 2Last Post: 04-26-2008, 10:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks