How to make a connection from javaME with MySQL

How to make a connection from javaME with MySQL

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
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
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
connection with MySQL to java.
connection with MySQL to java.   how to connect MySQL database with jsp
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 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.
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 use of the database connection. Database plays an important role in any
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
secure php mysql connection
secure php mysql connection  secure php mysql connection script
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
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
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using 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
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
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 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
iPhone Make Call from App
iPhone Make Call from App  iPhone Make Call Programmatically I have created an application in iPhone that has the functionality to make Call from App. I am just wondering how to make a call programmatically... is there any
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
connection of jsp with mysql - JSP-Servlet
Example of connection between JSP and MYSQL  Need an example of connection between JSP and MYSQL
How to connect to MySQL from command prompt?
How to connect to MySQL from command prompt? This video tutorial walks you... tutorial of: "How to connect to MySQL from command prompt?"ADS... learned How to connect to MySQL database from command prompt. Check all
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
how to make drop down list in JSF & fetch data Item from database
how to make drop down list in JSF & fetch data Item from database  how to make drop down list in JSF & fetch data Item from database
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
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
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc
how to make a radiobutton selected when retrieving data from database using struts framework and spring jdbc  how to make a radio button selected when retrieving data from database using struts framework and spring jdbc
How To Retrieve Image From From MySQL Using Java
How To Retrieve Image From From MySQL Using Java In this section we will discuss about how to retrieve image from the MySQL using Java. This example explains you about all the steps that how to retrieve image from MySQL database
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
Make Profit with Outsourcing,Profit from Outsourcing,How You Can Profit from Outsourcing
Make Profit with Outsourcing Introduction When a business is growing... not have the time or skills. How It Helps Outsourcing done the right way works... as a form of advertisement for your business. Networking Let us see how
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
How to retrive a particular record from database in php with mysql?
How to retrive a particular record from database in php with mysql?  Am using phpMyAdmin Database.In mysql database having 10 records. The field... record based on username and password. I dont know how to retrive in php with mysql
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
PHP Mysql Database Connection
PHP Mysql Database Connection       PHP Mysql Database Connection is used to build a connection... with ExampleADS_TO_REPLACE_1 The Tutorial illustrate an example from PHP Mysql Database
how to retrive the particular data from database in php with mysql?
how to retrive the particular data from database in php with mysql?  ..._db("samp", $con); $Name=$_POST['unames']; $data=mysql_query("SELECT * FROM tbl... like this.. <?php $con = mysql_connect("localhost","root
how to store JTree data hierarchically in mysql database from netbeans
how to store JTree data hierarchically in mysql database from netbeans  how to store JTree data hierarchically in mysql database from netbeans. I am new to this topics so I need a program and tables you are using in database
how to retrieve image from mysql using java - Java Beginners
how to retrieve image from mysql using java  hi i am using jsf and java IDE netbean,database mysql.how to retrieve image from mysql database. please help me   Hi friend, I am sending you a link. I hope
how to retreive data dynamically from mysql to drop down list
how to retreive data dynamically from mysql to drop down list   sir, i created a table in mysql and i inserted some values into the table through fron end using jsp , after storing the data successfully .i want to retrieve
connection
connection   how to make multiple database connection using jdbc
how do i make a phone call from my app without quitting my application
how do i make a phone call from my app without quitting my application  hi, I am working on creating a call application, i am making a call from my app through NSURL *targetUrl = [NSURL URLWithString:@"tel:123456789
How to make a ajax application which take data from textarea and that page is not refreshing.
How to make a ajax application which take data from textarea and that page is not refreshing.  I am doing a application in that i am using Spring Framework.I am having a text area and a submit button. On pressing submit Button
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes...:mysql://200.0.0.153:3306/snms"; Connection connection = null; ResultSet rs=null
schema extraction from mysql
schema extraction from mysql  hi i am completely new to MySql. i need... is not working. there is no username. 1)how do i findout username(its not assigned) and password? 2)how do i export schema from existing table? 3) how do i use

Ads