Sunday, 1 September 2013

Drop down list not binding with sqldatareader

Drop down list not binding with sqldatareader

i have a form with a collection of about five drop down . i have my query
as follows .
string sql = "SELECT a.clientID ,a.[cname],b.bid,b.[bname],c.contactID,
c.[name] FROM "
+ " dbo.[CLIENT] AS a INNER JOIN dbo.[BRANCH] AS b "
+ "ON a.clientID = b.clientID JOIN dbo.[CONTACT]
AS "
+ " c ON b.bid = c.bid ORDER BY a.clientID ";
i then followed and bind my drop down individually to their respective
columns as follows.
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
SqlDataReader reader = cmd.ExecuteReader();
drClient.Enabled = true;
drClient.DataSource = reader;
drClient.DataTextField = "cname";
drClient.DataValueField = "clientID";
drClient.DataBind();
drBranch.Enabled = true;
drBranch.DataSource = reader;
drBranch.DataTextField = "bname";
drBranch.DataValueField = "bid";
drBranch.DataBind();
drContact.Enabled = true;
drContact.DataSource = reader;
drContact.DataTextField = "name";
drContact.DataValueField = "contactID";
drContact.DataBind();
drEmail.Enabled = true;
drEmail.DataSource = reader;
drEmail.DataTextField = "name";
drEmail.DataValueField = "contactID";
drEmail.DataBind();
drFax.Enabled = true;
drFax.DataSource = reader;
drFax.DataValueField = "contactID";
drFax.DataTextField = "name";
drFax.DataBind();
when i run this, only the first drop down bind successfully. The rest
don't. I also try to loop through the reader by adding
while(reader.read())
{
then my bindings
}
the above also fails. I though of looping as below as well.
while(read.HasRows)
{
}
it still fails. I am confused,any help would be appreciated. thanks

Web proxy script in java or jsp

Web proxy script in java or jsp

Long story short, I want to integrate web proxy in my website.
After much reading, I stumble upon http://www.glype.com/ , but the problem
is they only provide PHP version.
My website is using java and jsp language, so I hope to have the script
written in these two languages.
While it's possible for me to write it myself, I really don't want to
reinvent the wheel, especially with thousands of web proxy out there.

casting values from an array to the findViewById ids

casting values from an array to the findViewById ids

public String getTexts(int i, int j, String[][] setTexts){
String id = new String();
return id = setTexts[i][j];
}
for (int i = 0; i < weights.length; i++) {
for (int j = 0; j < weights[i].length; j++) {
final EditText setTexts[i][j] =
(EditText)findViewById(R.id.getTexts(i,j,setTexts[][]));
}
}
I used a getter to get a value from a 2d array called "setTexts" that I
created before the shown code, containing the ids of the EditTexts that I
wanted to change. Then when I tried to use the method to get the ids, I
get "unexpected tokens" and a "cannot resolve method "getTexts". I also
tried casting but it didn't work.

CreateFile fails on opening lsass.exe

CreateFile fails on opening lsass.exe

I'm working on a program, which collects some statistics about processes,
which are running on the system.
I've got a code, which retrieves some routine information, such as
executable file version, publisher and so on.
The code works fine for me until I open lsass.exe. When I try to open file
for reading, CreateFile fails with error ERROR_FILE_NOT_FOUND.
Here is the code:
auto FileHandle
= CreateFile(file_to_process.c_str(), // C:\Windows\System32\lsass.exe
GENERIC_READ,
FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if ( INVALID_HANDLE_VALUE == FileHandle )
{
int err_v = GetLastError(); // ERROR_FILE_NOT_FOUND
}
This code is a part of a system service, which is running with 'SYSTEM'
privileges.

Saturday, 31 August 2013

java.lang.NumberFormatException: For input string:

java.lang.NumberFormatException: For input string:

I'm trying to convert a String timestamp to an Integer one and I'm using
postgres as DB.
@Column(name = "connecte_timestamp")
private Integer timestamp;
SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
Date aujourdhui = new Date();
this.timestamp = Integer.parseInt(formater.format(aujourdhui)
.replace("-", "").replace(" ", "").replace(":", ""));
the timestamp have bigint as a type in the DB. When I run my app, I get
the following stack trace :
java.lang.NumberFormatException: For input string: "01092013062024" at
java.lang.NumberFormatException.forInputString(Unknown Source) at
java.lang.Integer.parseInt(Unknown Source) at
java.lang.Integer.parseInt(Unknown Source) at
com.forum.beans.Connecte.(Connecte.java:26) at
com.forum.servlets.ListageForums.doGet(ListageForums.java:32) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at
java.lang.Thread.run(Unknown Source)
Any help please ?

Undefined reference to function in class

Undefined reference to function in class

main.cpp:
#include <iostream>
#include "pokemonList.h"
void pokemonLookup();
int main() {
pokemonLookup();
return 0;
}
void pokemonLookup() {
pokemonList pL;
std::cout<<std::endl<<"What Pokemon do you want to look up? ";
std::string pokemonLookup;
std::cin>>pokemonLookup;
pL.displayPokemon(pokemonLookup);
}
pokemonList.h:
#ifndef POKEMONLIST_H
#define POKEMONLIST_H
#include <iostream>
class pokemonList
{
private:
struct pokemonTemplate {
std::string pokemonName;
std::string pokemonMoves[3];
int pokemonLevel;
int baseATK;
int baseDEF;
int baseSPATK;
int baseSPDEF;
int baseSPEED;
};
pokemonTemplate bulbasaur;
pokemonTemplate pikachu;
public:
void displayPokemon(std::string pokemon);
protected:
};

I'm trying to find the sum of primes below million

I'm trying to find the sum of primes below million

I'm trying to find the sum of primes below millions..my code works when I
try to find the sum of primes below hundred thousands but when I go large
numbers it doesn't work....so I need some help to get this work for big
numbers...
import java.util.Scanner;
public class sumPrime {
public static void main (String args []){
long n = 2000000; int i; int j;int sum =0;
for (i=2; i <n; i++){
for (j=2; j<i; j++){
if (i%j==0){
break;
}
}
if (i==j){
sum +=i;
}
}
System.out.print(sum);
}
}