• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

retriving bit from Database

 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys

i am unable to get the data from the column of a table

the data type of that column is bit .but iam able to get remaining

column values properly iam getting an acii character for the records

of that column value having 1 and nothing printed for the records of

that column is 0

tha data base iam using is MySQl

i am getting all the values of the columns through getString() method

looking for your replies

regards
amir
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the method:

getBoolean()

of the ResultSet class is what you need. If you need more help, there is a more specialized forum here at the Java Ranch at: JDBC.

Kaydell
 
Amirtharaj Chinnaraj
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry guys i dont know my thread has already redirected

without knowing this i posted once again
 
Amirtharaj Chinnaraj
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaydell i tried what you suggested

but its not working

looking for your replies

regards
amir
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Amirtharaj Chinnaraj:
but its not working



This is almost never a usable description of a problem. What exactly did you try (show some code), and what exactly happened? TellTheDetails
 
Amirtharaj Chinnaraj
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ulf

i iam trying to write a java program using jdbc to create

sql file (to back up a particular table in a database)

iam getting almost done but iam facing a small problem

that iam not able to retive a the value from resultset

for a column of type bit

my code is


import java.io.File;
import java.io.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;

class sqlscript
{

static HashMap typeMap= new HashMap();
static
{
typeMap.put("TINYINT","int");
typeMap.put("BIGINT","int");
typeMap.put("BOOL","int");
typeMap.put("INTEGER","int");
typeMap.put("int unsigned","int");
typeMap.put("SMALLINT","int");
typeMap.put("bit","int");
typeMap.put("BIT","int");

typeMap.put("float","float");
typeMap.put("DOUBLE","float");
typeMap.put("DOUBLE PRECISIO","float");
typeMap.put("REAL","float");

typeMap.put("varchar","String");
typeMap.put("char","String");
typeMap.put("text","String");


typeMap.put("DATE","Date");
typeMap.put("time","Date");
typeMap.put("datetime","Date");
typeMap.put("timestamp","Date");




}





public static void main(String as[])
{
try
{
String query="insert into "+ " "+as[0]+" " +"values (";
String tableName=as[0];
ArrayList queryList=new ArrayList();
boolean tableNameCorrect=false;
Class c= Class.forName("com.mysql.jdbc.Driver");//drive class for jdbc

DriverManager.registerDriver((Driver)c.newInstance());
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","admin");
DatabaseMetaData dbmeta= con.getMetaData();
ResultSet rs= dbmeta.getTables("test",null,null,null);
ResultSet rstype=dbmeta.getTypeInfo();
while(rstype.next())
{
System.out.println(" type " +rstype.getString(1));
}

while(rs.next())
{
if(tableName.equalsIgnoreCase(rs.getString(3)))
{
tableNameCorrect=true;
System.out.println("the table name entered is exixt in Database ");
break;
}

}

if(!tableNameCorrect)
{
System.out.println("the table name entered is does not exixt in Database ");
System.exit(0);
}

ResultSet columnName=dbmeta.getColumns("test",null,as[0],null);
Statement st=con.createStatement();
ResultSet data=st.executeQuery("select * from "+as[0]);
String qvalue="";
while(data.next())
{
int i=1;
while(columnName.next())
{

System.out.println( " "+ (String)columnName.getString(6) + " "+(String)columnName.getString(4));
String type=(String)typeMap.get((String)columnName.getString(6));
// System.out.println( " " +type);

if(i>1)
qvalue=qvalue+",";

if(type.equalsIgnoreCase("int"))
{
qvalue=qvalue+data.getString((String)columnName.getString(4));


}

if(type.equalsIgnoreCase("Date"))
qvalue=qvalue+"'"+data.getString((String)columnName.getString(4))+"'";

if(type.equalsIgnoreCase("String"))
qvalue=qvalue+"'"+data.getString((String)columnName.getString(4))+"'";


if(type.equalsIgnoreCase("float"))
qvalue=qvalue+data.getString((String)columnName.getString(4));

if(type.equalsIgnoreCase("Bit"))
{
System.out.println("bool ");
qvalue=qvalue+data.getString((String)columnName.getString(4));
boolean b=columnName.getBoolean(4);
System.out.println();
System.out.println();
}

if(type.equalsIgnoreCase("bit"))
{
System.out.println("bool ");
qvalue=qvalue+data.getString((String)columnName.getString(4));
System.out.println();
System.out.println("bool ");
System.out.println();
}
i++;

}

columnName.beforeFirst();
System.out.println( query+ " " + qvalue);
System.out.println();
qvalue="";
}

}//insert into test.user values(5,'amir','raj');

/* try
{
File f= new File("sqlscript.sql");
f.createNewFile();
FileWriter fr= new FileWriter(f);
BufferedWriter outputB= new BufferedWriter(fr);

outputB.write("insert into table ");
//outputB.newLine();
outputB.write("insert into table ");
outputB.close();
}*/

catch(Exception ex)
{
System.out.println(" print "+ex );

}

}
}

iam getting some ascii values for bit columns but others are fine

apart from that iam having a doubt that is that two differnt types

bit and BIT are availaibe in MYSQL

regards
amir
[ June 12, 2007: Message edited by: Amirtharaj Chinnaraj ]
 
    Bookmark Topic Watch Topic
  • New Topic