android geting data from sql

Posted by sagar on Server Fault See other posts from Server Fault or by sagar
Published on 2012-06-07T10:41:18Z Indexed on 2012/06/07 10:42 UTC
Read the original article Hit count: 309

Filed under:
|
|

Hello i m new to android. i wont to connect to sql server for store and get data so so me one can help me sending code of android for do it.. i had tried to do tht with java nd it was workink but now i wont to create a aplication for android my java code is ::

import java.sql.*; public class MysqlTest { public static void main (String[] args) { Connection conn = null; try { String userName = "pietro"; //change it to your username String password = "pietro"; //change it to your password

String url = "jdbc:mysql://192.168.0.67:3306/registro";

Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, userName, password);

Statement s = (Statement) conn.createStatement(); // code for create a tabel in server

s.execute("create table School2 (rolno integer,sub text)"); // code for create a tabel in server

s.execute("insert into School2(rolno,sub)values(10,'java')"); //code for add value in tabel
s.execute("select rolno,sub from School2");//code for add value in tabel

s.close();
System.out.println("Database connection established");
}


catch (Exception e)
{
System.err.println("Cannot connect to database server");
}


finally
{

    if (conn != null)
{

        try
{
conn.close ();
System.out.println("Database connection terminated");
}

        catch (Exception e) { /* ignore close errors */ }
       }
     }
  }
}

© Server Fault or respective owner

Related posts about mysql

Related posts about java