Recently made an android mysql query the database server, using JDBC, but I do not know why android is always connected to the project is not built on the database. Another own java files can be accessed locally or remotely access the project is not built, check out the two days have not been resolved, seek expert advice.
public class GetData {
private Connection connection;
private Statement statement;
private ResultSet resultSet;
/ / Create connection conn ()
public void Conn () throws ClassNotFoundException, SQLException {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc: mysql :/ / 10.28.52.193:3306 / schedule"; / / 10.28.52.193 localhost
String user = "honghu";
String password = "920326";
Class.forName (driver);
connection = DriverManager.getConnection (url, user, password);
if (! connection.isClosed ()) {
System.out.println ("successful connection");
}
}
/ / Query
public Student find (Integer id) throws SQLException {
Student student = null;
String sql = "select * from student where stunum = 20103174";
statement = (Statement) connection.createStatement ();
resultSet = statement.executeQuery (sql);
while (resultSet.next ()) {
String name = resultSet.getString ("name") toString ();.
/ / System.out.println (name);
student = new Student (name);
}
return student;
}}
/ / This is the unit test in the test method
public void testConn () {
GetData getData = new GetData ();
try {
getData.Conn ();
Log.i (TAG, "successful connection");
} Catch (ClassNotFoundException e) {
Log.e (TAG, "failed 001");
} Catch (SQLException e) {
/ / TODO Auto-generated catch block
Log.e (TAG, "failed 002");
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Oh good regressed. . . I really have not seen a direct link database android success stories. . With web platform is generally used as a transit
Reply:
Do not be lazy, always do your own server it. .
Reply:
The key is the amount still not PHP, so I want to use JDBC directly connected.
Reply:
Haha, yes, the landlord is very powerful!
Reply:
lz very powerful ah! ! !
Reply:
I also depressed, but also get less connection connection object,
But I found a document on the Internet, on the android remote connection mysql server details see: http://www.ways2u.com/?post=197
I built environment windows + mysql directory structure without his instructions, please see the next moderator, if you can find a solution. Help brothers explanatory.
Reply:
There should be no reference to jar package to the project, or reference the wrong way. The latest adt 18 at compile external jar package has changed the way, build path way invalid, the correct approach should be: Right-click on the project -> Create a new folder libs, find the driver package you need, ctrl + c to copy jar package -> selected item in the list libs folder -> ctrl + v, jar package is automatically added to the project.
Reply:
Be transit, webserver, can be
Reply:
I have been engaged before android mysql through JDBC connection, you can look http://blog.csdn.net/luzhenrong45/article/details/8933515
Reply:
Transit must do it? Do not directly linked to the same manner as SQLite it?
Reply:
Must transit, and the connection is not the same sqlite
No comments:
Post a Comment