How to make a connection from javaME with MySQL

Ads

 
 

Share on Google+Share on Google+

Amirul
How to make a connection from javaME with MySQL
1 Answer(s)      8 years ago
Posted in : SQL
Ads
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

Ads









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 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
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.
How to delete data from MySQL?
How to delete data from MySQL?  Hi, How I can conditionally delete the data from MySQL Table? Thanks   Hi, You can use the where clause to conditionally delete the data from MySQL database table. Here is some query
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
connection with MySQL to java.
connection with MySQL to java.   how to connect MySQL database with jsp
how to fetch image from mysql using jsp
how to fetch image from mysql using jsp  how to fetch image from mysql using jsp
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
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
How to retrieve image from mysql database in JSP?
How to retrieve image from mysql database in JSP?  Hi, I need JSP same codes for learning to get image which is stored in MySQL Database. How to retrieve image from mysql database in JSP? Thanks   Hi, You can write
secure php mysql connection
secure php mysql connection  secure php mysql connection script
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
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
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
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 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
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
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
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 count unique and duplicate values from one table in mysql?
how to count unique and duplicate values from one table in mysql?  I have use EMP table.I want to count unique and duplicate records from emp table and how to use in java program
How to connect to MySQL from command prompt?
How to connect to MySQL from command prompt? This video tutorial walks you through the steps to connect to MySQL from command prompt in Windows machine... of: "How to connect to MySQL from command prompt?" Then is sure
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 display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance

Ads

 
Advertisement null

Ads