Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa SQL How to make a connection from javaME with MySQL
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Amirul
How to make a connection from javaME with MySQL
1 Answer(s)      5 years and 7 months ago
Posted in : SQL



Advertisement
View Answers

March 12, 2009 at 4:34 AM


Hi friend,

Code to help in solving the problem :

import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;

public class RecordDataBase extends MIDlet {
static final String DBNAME = "RecordDataBase";

public void startApp(){
RecordStore rs = null;
try{
RecordStore.deleteRecordStore(DBNAME);
} catch(Exception e){}

try{
rs = RecordStore.openRecordStore(DBNAME, true);
byte[] data1 = "First Record".getBytes();
byte[] data2 = "Second Record".getBytes();
byte[] data3 = " Third Record".getBytes();
data3[0] = 0;
data3[data3.length-1] = (byte) -1;
rs.addRecord(data1, 0, data1.length);
rs.addRecord(data2, 0, data2.length);
rs.addRecord(data3, 0, data3.length);
storeData(rs, System.out);
rs.closeRecordStore();
}catch(RecordStoreException e){
System.out.println(e);
}
notifyDestroyed();
}

public void pauseApp(){}

public void destroyApp(boolean unconditional){}

public void storeData(RecordStore rs, PrintStream out){
if(rs == null) return;
StringBuffer hexLine = new StringBuffer();
StringBuffer charLine = new StringBuffer();

try{
int lastID = rs.getNextRecordID();
byte[] data = new byte[100];
int size;

for(int i = 1; i < lastID; ++i){
try{
size = rs.getRecordSize(i);
if(size > data.length){
data = new byte[size * 2];
}
out.println("-------------------------------------");
out.println("Size = " + size);
out.println("-----------------------------------");
rs.getRecord(i, data, 0);
storeRecord(data, size, out, hexLine, charLine, 16);
out.println(" ");
} catch(InvalidRecordIDException e){
continue;
}
}
} catch( RecordStoreException e ){
out.println(e);
}
}

private void storeRecord(byte[] data, int size, PrintStream out, StringBuffer

hexLine, StringBuffer charLine, int maxLen ){
if(size == 0) return;
hexLine.setLength(0);
charLine.setLength(0);
int count = 0;
for(int i = 0; i < size; ++i){
char b = (char) (data[i] & 0xFF);

if(b < 0x10){
hexLine.append('0');
}
hexLine.append(Integer.toHexString(b));
hexLine.append(' ');

if((b >= 32 && b <= 127) ||
Character.isDigit(b) ||
Character.isLowerCase(b) ||
Character.isUpperCase(b)){
charLine.append((char)b);
} else {
charLine.append(' ');
}

if(++count >= maxLen || i == size-1){
while(count++ < maxLen){
hexLine.append(" ");
}
hexLine.append(' ');
hexLine.append(charLine.toString());
out.println( hexLine.toString());
hexLine.setLength(0);
charLine.setLength(0);
count = 0;
}
}
}
}

Thanks


Related Tutorials/Questions & Answers:
How to make a connection from javaME with MySQL - SQL
How to make a connection from javaME with MySQL  Hi i`m a final year student from one of university from malaysia, I have a problem about my final... and MySQL. I really hoping someone could help me on my final year project
How to make a connection from javaME with MySQL - SQL
How to make a connection from javaME with MySQL  Hi i`m a final year student from one of university from malaysia, I have a problem about my final... and MySQL. I really hoping someone could help me on my final year project
Advertisements
how to write and read text for javaME
how to write and read text for javaME  Hi. I have tried ur read/write coding but why i didnt get the o/p just like urs. do i have to add anything from the library? i want to type multiple line on text file then, read it from
socket connection: how to parse data from server?
socket connection: how to parse data from server?  hi, I am a j2me programmer,i want to retrieve some data from server using socket connection,I h'v established the connection through the port and getting the data from the server
how to auto generate number in jsp with the database connection mysql for employee number?
how to auto generate number in jsp with the database connection mysql for employee number?  how to auto generate number in jsp with the database connection mysql for employee number?   <%@page import="java.sql.
how to auto generate number in jsp with the database connection mysql for employee number?
how to auto generate number in jsp with the database connection mysql for employee number?  how to auto generate number in jsp with the database connection mysql for employee number?   <%@page import="java.sql.
connection with MySQL to java.
connection with MySQL to java.   how to connect MySQL database with jsp
How to make phone call from web application
How to make phone call from web application  I'm creating an XHTML... to make call to a specific number when user clicks a particular button. Please suggest on how to do this. I'm new to this. Thanks in advance
how to connect mysql from gui?
how to connect mysql from gui?  i am unable to connet to mysql server from my projet that is gui for mysql...can anyone help me in this...its urgent? i have to connet to mysql from gui..   Hi Friend, Try the following
Java Mysql Connection Example
Java Mysql Connection Example We are going to discus how to connect  MySQL in java. We have been provide some classes and API with which we will make... (should be kept into lib folder). In this example how to connect the MySQL
secure php mysql connection
secure php mysql connection  secure php mysql connection script
How to update mysql from 5.1 to 5.5
How to update mysql from 5.1 to 5.5  How to update mysql from 5.1 to 5.5
how to fetch image from mysql using jsp
how to fetch image from mysql using jsp  how to fetch image from mysql using jsp
connection to mysql in jsp
connection to mysql in jsp  please i got this error message when trying to connect to mysql database in jsp. Unknown character set: 'utf8mb4
connection of php to MySQL.
connection of php to MySQL.  I have a query on connection of php to MySQL. Website's serverspace by godaddy and provides phpmyadmin(interface... code, make the connection and run the query.. Connection is made perfectly
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
DriverClass hibernate mysql connection.
DriverClass hibernate mysql connection.  What is DriverClass in Hibernate using mysql connection?   DriverClass implements java.sql.Driver.... the connection url as- <property name="connection.url">jdbc:mysql://localhost
JSP - MySQL - Connection
JSP - MySQL - Connection  I can't connect mysql using jsp in my... from the server was 1,300,257,595,704 milliseconds ago. The last packet sent... to resolve this problem.I set classpath for the mysql connector jar (/home/aghiltu/apache
jsp/mysql connection
jsp/mysql connection  I am puttng the following files in the lib folder of jdk to connect jsp and mysql and in the lib folder of tomacat and in the lib folder of project of netbeans but I am unable to to connect jsp and mysql
jsp/mysql connection
jsp/mysql connection  I am puttng the following files in the lib folder of jdk to connect jsp and mysql and in the lib folder of tomacat and in the lib folder of project of netbeans but I am unable to to connect jsp and mysql
How to access (MySQL)database from J2ME?
How to access (MySQL)database from J2ME?  I am new to J2ME. I am using NetBeans. Can anyone help me? How to access (MySQL)database from J2ME? ( I search a lot I found that there is need to access database through servlet
MySql PHP Connection String - PHP
MySql PHP Connection String  i need a MySql PHP Connection String, is it possible to do pooling in between
How to make a list from file text in J2ME - Java Beginners
How to make a list from file text in J2ME  I was trying to make a method that read file from text and make a list of it, I have tried ReadHelpText method and want to make some improvement, I've tried like this private String
connection of jsp with mysql - JSP-Servlet
Example of connection between JSP and MYSQL  Need an example of connection between JSP and MYSQL
connection of jsp with mysql - JSP-Servlet
connection of jsp with mysql  can anybody tell me about connection of JSP with MYSQL? and also tell me which version is compatible with tomcat 4.1 i am using tomcat 4.1, MYSQL 5.0 but i have problem with connection
MySQL Connection String
MySQL Connection String       This section gives you brief description of MySQL connection string. For the connection in mysql, we need some information about database like server
PHP Mysql Database Connection
The Tutorial illustrate an example from PHP Mysql Database Connection... PHP Mysql Database Connection       PHP Mysql Database Connection is used to build a connection
connection with mysql with jstl - JSP-Servlet
connection with mysql with jstl  hi, i m working on jstl . i hv done connection in MS -Access with JSTL . The code is working well. but when i am trying to connect database with mysql 5.0 it is creating problem. Plz tell me
how to insert and retrieve an image from mysql using java - Java Beginners
how to insert and retrieve an image from mysql using java  how to insert and retrieve an image from mysql using java?  Hi friend, Code... SQLException { // declare a connection by using Connection interface
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
 

 

 

DMCA.com