Easy Question -String conversion to type int
Greetings Java Gurus,
What is the best way to convert a String to type int?
I have looked through the JAVA API documentation and have found the following possibilites but I cannot get the JAVA syntax right :(
Java.lang.decode
public static Integer decode(String nm)
Decodes a String into an Integer.
Java.lang.valueOf
public static Integer valueOf(String s)
Returns a new Integer object initialized to the value of the specified String.
1.) If anyone has an easy way to accomplish this let me know.
2.) If anyone could give me the proper JAVA syntax for the above commands?
Any Ideas or Suggestions will be greatly appreciated!
-Chibi_neko
These are all methods of java.lang.Integer class.
1. public static Integer decode( String nm )int a = -1;
try {
a = Integer.decode( "1234" );
} catch( NumberFormatException nfe ) {
a = -1;
}2. public static int parseInt( String s )int a = -1;
try {
a = Integer.parseInt( "1234" );
} catch( NumberFormatException nfe ) {
a = -1;
}3. public static int valueOf( String s )Integer a = null;
try {
a = Integer.valueOf( "1234" );
} catch( NumberFormatException nfe ) {
a = null;
}
Similar Messages
-
Replacing String month with type Int - What to do!?!
import java.util.Scanner;
public class Date
private String month;
private int day;
private int year; //a four digit number.
public Date( )
month = "January";
day = 1;
year = 1000;
public Date(int monthInt, int day, int year)
setDate(monthInt, day, year);
public Date(String monthString, int day, int year)
setDate(monthString, day, year);
public Date(int year)
setDate(1, 1, year);
public Date(Date aDate)
if (aDate == null)//Not a real date.
System.out.println("Fatal Error.");
System.exit(0);
month = aDate.month;
day = aDate.day;
year = aDate.year;
public void setDate(int monthInt, int day, int year)
if (dateOK(monthInt, day, year))
this.month = monthString(monthInt);
this.day = day;
this.year = year;
else
System.out.println("Fatal Error");
System.exit(0);
public void setDate(String monthString, int day, int year)
if (dateOK(monthString, day, year))
this.month = monthString;
this.day = day;
this.year = year;
else
System.out.println("Fatal Error");
System.exit(0);
public void setDate(int year)
setDate(1, 1, year);
public void setYear(int year)
if ( (year < 1000) || (year > 9999) )
System.out.println("Fatal Error");
System.exit(0);
else
this.year = year;
public void setMonth(int monthNumber)
if ((monthNumber <= 0) || (monthNumber > 12))
System.out.println("Fatal Error");
System.exit(0);
else
month = monthString(monthNumber);
public void setDay(int day)
if ((day <= 0) || (day > 31))
System.out.println("Fatal Error");
System.exit(0);
else
this.day = day;
public int getMonth( )
if (month.equals("January"))
return 1;
else if (month.equals("February"))
return 2;
else if (month.equalsIgnoreCase("March"))
return 3;
else if (month.equalsIgnoreCase("April"))
return 4;
else if (month.equalsIgnoreCase("May"))
return 5;
else if (month.equals("June"))
return 6;
else if (month.equalsIgnoreCase("July"))
return 7;
else if (month.equalsIgnoreCase("August"))
return 8;
else if (month.equalsIgnoreCase("September"))
return 9;
else if (month.equalsIgnoreCase("October"))
return 10;
else if (month.equals("November"))
return 11;
else if (month.equals("December"))
return 12;
else
System.out.println("Fatal Error");
System.exit(0);
return 0; //Needed to keep the compiler happy
public int getDay( )
return day;
public int getYear( )
return year;
public String toString( )
return (month + " " + day + ", " + year);
public boolean equals(Date otherDate)
return ( (month.equals(otherDate.month))
&& (day == otherDate.day) && (year == otherDate.year) );
public boolean precedes(Date otherDate)
return ( (year < otherDate.year) ||
(year == otherDate.year && getMonth( ) < otherDate.getMonth( )) ||
(year == otherDate.year && month.equals(otherDate.month)
&& day < otherDate.day) );
public void readInput( )
boolean tryAgain = true;
Scanner keyboard = new Scanner(System.in);
while (tryAgain)
System.out.println("Enter month, day, and year.");
System.out.println("Do not use a comma.");
String monthInput = keyboard.next( );
int dayInput = keyboard.nextInt( );
int yearInput = keyboard.nextInt( );
if (dateOK(monthInput, dayInput, yearInput) )
setDate(monthInput, dayInput, yearInput);
tryAgain = false;
else
System.out.println("Illegal date. Reenter input.");
private boolean dateOK(int monthInt, int dayInt, int yearInt)
return ( (monthInt >= 1) && (monthInt <= 12) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
private boolean dateOK(String monthString, int dayInt, int yearInt)
return ( monthOK(monthString) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
private boolean monthOK(String month)
return (month.equals("January") || month.equals("February") ||
month.equals("March") || month.equals("April") ||
month.equals("May") || month.equals("June") ||
month.equals("July") || month.equals("August") ||
month.equals("September") || month.equals("October") ||
month.equals("November") || month.equals("December") );
private String monthString(int monthNumber)
switch (monthNumber)
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
default:
System.out.println("Fatal Error");
System.exit(0);
return "Error"; //to keep the compiler happy
}My question is that if I were to change the String month in the instance variables to type int, what changes do I make to the code to make this work WITHOUT changing the method headings and it also says that none of the type String paraenters should change to type int. I need to redefine the methods to make it work. I've been at this for hours and am just stuck so this is the reason for my early morning post.import java.util.Scanner;
public class Date
private int month;
private int day;
private int year; //a four digit number.
public Date( )
month = 1;
day = 1;
year = 1000;
public Date(int monthInt, int day, int year)
setDate(monthInt, day, year);
public Date(String monthString, int day, int year)
setDate(monthString, day, year);
public Date(int year)
setDate(1, 1, year);
public Date(Date aDate)
if (aDate == null)//Not a real date.
System.out.println("Fatal Error.");
System.exit(0);
month = aDate.month;
day = aDate.day;
year = aDate.year;
public void setDate(int monthInt, int day, int year)
if (dateOK(monthInt, day, year))
this.month = monthInt;
this.day = day;
this.year = year;
else
System.out.println("Fatal Error");
System.exit(0);
public void setDate(String monthString, int day, int year)
if (dateOK(monthString, day, year))
this.month = monthStringToInt(monthString);
this.day = day;
this.year = year;
else
System.out.println("Fatal Error");
System.exit(0);
public void setDate(int year)
setDate(1, 1, year);
public void setYear(int year)
if ( (year < 1000) || (year > 9999) )
System.out.println("Fatal Error");
System.exit(0);
else
this.year = year;
public void setMonth(int monthNumber)
if ((monthNumber <= 0) || (monthNumber > 12))
System.out.println("Fatal Error");
System.exit(0);
else
month = monthNumber;
public void setDay(int day)
if ((day <= 0) || (day > 31))
System.out.println("Fatal Error");
System.exit(0);
else
this.day = day;
public int getMonth( )
return month;
public int getDay( )
return day;
public int getYear( )
return year;
public String toString( )
return (month + " " + day + ", " + year);
public boolean equals(Date otherDate)
return ( (month == otherDate.month)
&& (day == otherDate.day) && (year == otherDate.year) );
public boolean precedes(Date otherDate)
return ( (year < otherDate.year) ||
(year == otherDate.year && getMonth( ) < otherDate.getMonth( )) ||
(year == otherDate.year && month == otherDate.month
&& day < otherDate.day) );
public void readInput( )
boolean tryAgain = true;
Scanner keyboard = new Scanner(System.in);
while (tryAgain)
System.out.println("Enter month, day, and year.");
System.out.println("Do not use a comma.");
String monthInput = keyboard.next( );
int dayInput = keyboard.nextInt( );
int yearInput = keyboard.nextInt( );
if (dateOK(monthInput, dayInput, yearInput) )
setDate(monthInput, dayInput, yearInput);
tryAgain = false;
else
System.out.println("Illegal date. Reenter input.");
private boolean dateOK(int monthInt, int dayInt, int yearInt)
return ( (monthInt >= 1) && (monthInt <= 12) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
private boolean dateOK(String monthString, int dayInt, int yearInt)
return ( monthOK(monthString) &&
(dayInt >= 1) && (dayInt <= 31) &&
(yearInt >= 1000) && (yearInt <= 9999) );
private boolean monthOK(String month)
return (month.equals("January") || month.equals("February") ||
month.equals("March") || month.equals("April") ||
month.equals("May") || month.equals("June") ||
month.equals("July") || month.equals("August") ||
month.equals("September") || month.equals("October") ||
month.equals("November") || month.equals("December") );
private String monthString(int monthNumber)
switch (monthNumber)
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
case 12:
return "December";
default:
System.out.println("Fatal Error");
System.exit(0);
return "Error"; //to keep the compiler happy
private int monthStringToInt(String monthString) {
if (monthString.equals("January")) return 1;
else if (monthString.equals("February")) return 2;
else if (monthString.equals("March")) return 3;
else if (monthString.equals("April")) return 4;
else if (monthString.equals("May")) return 5;
else if (monthString.equals("June")) return 6;
else if (monthString.equals("July")) return 7;
else if (monthString.equals("August")) return 8;
else if (monthString.equals("September")) return 9;
else if (monthString.equals("October")) return 10;
else if (monthString.equals("November")) return 11;
else if (monthString.equals("December")) return 12;
else return -1;
}I've added one method: monthStringToInt to convert "January", "February" into an integer value. There are probably better ways to do this (Calendar), but this involes no other classes. -
Conversion failed when converting the varchar value to data type int error
Hi, I am working on a report which is off of survey information and I am using dynamic pivot on multiple columns.
I have questions like Did you use this parking tag for more than 250 hours? If yes specify number of hours.
and the answers could be No, 302, 279, No and so on....
All these answers are of varchar datatype and all this data comes from a partner application where we consume this data for internal reporting.
When I am doing dynamic pivot I get the below error.
Error: Conversion failed when converting the varchar value 'No' to data type int.
Query
DECLARE @Cols1 VARCHAR(MAX), @Cols0 VARCHAR(MAX), @Total VARCHAR(MAX), @SQL VARCHAR(MAX)
SELECT @Cols1 = STUFF((SELECT ', ' + QUOTENAME(Question) FROM Question GROUP BY Question FOR XML PATH('')),1,2,'')
SELECT @Cols0 = (SELECT ', COALESCE(' + QUOTENAME(Question) + ',0) as ' + QUOTENAME(Question) FROM Question GROUP BY Question FOR XML PATH(''))
SET @SQL = 'SELECT QID, QNAME' + @Cols0 + '
FROM (SELECT QID, QNAME, ANSWERS, Question
FROM Question) T
PIVOT (MAX(ANSWERS) FOR Question IN ('+@Cols1+')) AS P'
EXECUTE (@SQL)
I am using SQL Server 2008 R2.
Please guide me to resolve this.
Thanks in advance..........
Ionecreate table questions (QID int, QNAME varchar(50), ANSWERS varchar(500), Question varchar(50))
Insert into questions values(1,'a','b','c'), (2,'a2','b2','c2')
DECLARE @Cols1 VARCHAR(MAX), @Cols0 VARCHAR(MAX), @Total VARCHAR(MAX), @SQL VARCHAR(MAX)
SELECT @Cols1 = STUFF((SELECT ', ' + QUOTENAME(Question) FROM Questions GROUP BY Question FOR XML PATH('')),1,2,'')
SELECT @Cols0 = (SELECT ', COALESCE(' + QUOTENAME(Question) + ',''0'') as ' + QUOTENAME(Question) FROM Questions GROUP BY Question FOR XML PATH(''))
SET @SQL = 'SELECT QID, QNAME' + @Cols0 + '
FROM (SELECT QID, QNAME, ANSWERS, Question
FROM Questions) T
PIVOT (MAX(ANSWERS) FOR Question IN ('+@Cols1+')) AS P'
EXECUTE (@SQL)
drop table questions -
Thank you for your help!!!
I've created a stored procedure to return results as xml. I'm having trouble figuring out why I'm getting the error message "Conversion failed when converting the nvarchar value '<tr>.....'
to data type int. It seems like the system doesn't know that I'm returning a string... Or, I'm doing something that I just don't see.
ALTER PROCEDURE [dbo].[p_getTestResults]
@xml NVARCHAR(MAX) OUTPUT
AS
BEGIN
CREATE TABLE #Temp
[TestNameId] int,
[MaxTestDate] [DateTime],
[Name] [nvarchar](50),
[Duration] [varchar](10)
DECLARE @body NVARCHAR(MAX)
;WITH T1 AS
SELECT DISTINCT
Test.TestNameId
, replace(str(Test.TotalTime/3600,len(ltrim(Test.TotalTime/3600))+abs(sign(Test.TotalTime/359999)-1)) + ':' + str((Test.TotalTime/60)%60,2)+':' + str(Test.TotalTime%60,2),' ','0') as Duration
,MaxTestDate = MAX(TestDate) OVER (PARTITION BY TM.TestNameId)
,TestDate
,TM.Name
,Test.TotalTime
,RowId = ROW_NUMBER() OVER
PARTITION BY
TM.TestNameId
ORDER BY
TestDate DESC
FROM
Test
inner join TestName TM on Test.TestNameID = TM.TestNameID
where not Test.TestNameID in (24,25,26,27)
INSERT INTO #Temp
SELECT
T1.TestNameId
,T1.MaxTestDate
,T1.[Name]
,T1.Duration
FROM
T1
WHERE
T1.RowId = 1
ORDER BY
T1.TestNameId
SET @body ='<html><body><H3>TEST RESULTS INFO</H3>
<table border = 1>
<tr>
<th> TestNameId </th> <th> MaxTestDate </th> <th> Name </th> <th> Duration </th></tr>'
SET @xml = CAST((
SELECT CAST(TestNameId AS NVARCHAR(4)) as 'td'
, CAST([MaxTestDate] AS NVARCHAR(11)) AS 'td'
, [Name] AS 'td'
, CAST([Duration] AS NVARCHAR(10)) AS 'td'
FROM #Temp
ORDER BY TestNameId
FOR XML PATH('tr'), ELEMENTS ) AS NVARCHAR(MAX))
SET @body = @body + @xml +'</table></body></html>'
DROP TABLE #Temp
RETURN @xml
END
closlYour dont need RETURN inside SP as you've declared @xml already as an OUTPUT parameter. Also you can RETURN only integer values using RETURN statement inside stored procedure as that's default return type of SP.
so just remove RETURN statement and it would work fine
To retrieve value outside you need to invoke it as below
DECLARE @ret nvarchar(max)
EXEC dbo.[P_gettestresults] @ret OUT
SELECT @ret
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Conversion from string "20041023 " to type 'Date' is not valid.
Hi ,
I have a table with one of the column(EmpHiredate) datatype is char(10). It has value like "20141023". I need to display this value as date format(dd/mm/yyyy) in report.
Following methods i tried in textbox expression but no luck.
=Format(Fields!EmpHireDate.Value,"dd/MM/yyyy")
=Cdate(Fields!EmpHireDate.Value)
Error:
[rsRuntimeErrorInExpression] The Value expression for the textrun ‘EmpHireDate.Paragraphs[0].TextRuns[0]’ contains an error: Conversion from string "20041023 " to type 'Date' is not valid.
Is it possible to convert string to date using SSRS textbox expression ? Can anyone help me with the solution.
Thanks,
KittuHi Jmcmullen,
Found one more issue on the same. I have one value like "00000000" for the column(EmpHiredate)
, when i use above expression values(ex:"20141023")
are displaying in dd/MM/yyyy format in report except value like "00000000" and giving following error:
[rsRuntimeErrorInExpression] The Value expression for the textrun ‘EmpHireDate.Paragraphs[0].TextRuns[0]’ contains an error: Conversion from string "0000/00/00" to type 'Date' is not valid.
Even i tried to pass its original value("00000000") as below but no luck.
=IIF(Fields!EmpHireDate.Value = "00000000","00000000",Format(CDATE(MID(Fields!EmpHireDate.Value,1,4) + "/" + MID(Fields!EmpHireDate.Value,5,2) + "/" + MID(Fields!EmpHireDate.Value,7,2)),"dd/MM/yyyy"))
Also tried this:
=IIF(Fields!EmpHireDate.Value = "00000000","2000/10/21",Format(CDATE(MID(Fields!EmpHireDate.Value,1,4) + "/" + MID(Fields!EmpHireDate.Value,5,2) + "/" + MID(Fields!EmpHireDate.Value,7,2)),"dd/MM/yyyy"))
Please Suggest.
Thanks ,
Kittu -
Conversion failed when converting the varchar value to data type int
Hi, I am unable to resolve this error and would like some assistance please.
The below query produces the following error message -
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'NCPR' to data type int.
Select Pc2.Assess,
Select Pc1.Title
From Pc1
Where Pc1.Assess = Pc2.Assess
) [Title]
From Pc2
However, when I run the query below I get the results shown in the image . Ie. nothing. Pc1 & Pc2 are aliases and are the same table and the assess field is an int. I found NCPR in one cell but that column (prop) is not used in the query. The table
is nearly 25k rows.
SELECT * FROM Pc1 WHERE Pc1.Assess LIKE '%NCPR%' OR ISNUMERIC(Pc1.Assess) = 0
Thank youWHERE ISNUMERIC(id) = 1 and there are obviously no 'NCPR' records in the view as per my previous post.
That is a bad assumption - SQL Server does not have to evaluate the query in the order you are expecting it to.
Take this simple example
CREATE TABLE #example
col1 VARCHAR(50) NOT NULL
INSERT INTO #example VALUES ('1'), ('2'), ('NaN')
SELECT * FROM
SELECT * FROM #example
WHERE ISNUMERIC(col1) = 1
) X
(3 row(s) affected)
col1
1
2
(2 row(s) affected)
compare to
CREATE TABLE #example
col1 VARCHAR(50) NOT NULL
INSERT INTO #example VALUES ('1'), ('2'), ('NaN')
SELECT * FROM
SELECT * FROM #example
WHERE ISNUMERIC(col1) = 1
) X
WHERE col1 = 1
(3 row(s) affected)
col1
1
Msg 245, Level 16, State 1, Line 8
Conversion failed when converting the varchar value 'NaN' to data type int. -
Easy Question: How to split concatenated string into multiple rows?
Hi folks,
this might be an easy question.
How can I split a concatenated string into multiple rows using SQL query?
INPUT:
select 'AAA,BBB,CC,DDDD' as data from dualDelimiter = ','
Expected output:
data
AAA
BBB
CCC
DDDDI'm looking for something kind of "an opposite for 'sys_connect_by_path'" function.
Thanks,
TomasHere is the SUBSTR/INSTR version of the solution:
SQL> WITH test_data AS
2 (
3 SELECT ',' || 'AAA,BBB,CC,DDDD' || ',' AS DATA FROM DUAL
4 )
5 SELECT SUBSTR
6 (
7 DATA
8 , INSTR
9 (
10 DATA
11 , ','
12 , 1
13 , LEVEL
14 ) + 1
15 , INSTR
16 (
17 DATA
18 , ','
19 , 1
20 , LEVEL + 1
21 ) -
22 INSTR
23 (
24 DATA
25 , ','
26 , 1
27 , LEVEL
28 ) - 1
29 ) AS NEW_STRING
30 FROM test_data
31 CONNECT BY LEVEL <= LENGTH(REGEXP_REPLACE(DATA,'[^,]','')) - 1
32 /
NEW_STRING
AAA
BBB
CC
DDDD -
I have created the following trigger that fires instead of an UPDATE statement and copies the altered data over to an Audit table before proceeding with the requested UPDATE. After doing so, I wrote a simple UPDATE statement for testing:
UPDATE Products
SET ProductCode = 'XYZ 2014', ProductName = 'Special Edition Tamborine', ListPrice = 74.99, DiscountPercent = .5
WHERE ProductID = 28;
When I run this, I get the following message:
Msg 245, Level 16, State 1, Procedure Products_UPDATE, Line 14
Conversion failed when converting the varchar value 'X' to data type int.
Here is my trigger:
IF OBJECT_ID('Products_UPDATE') IS NOT NULL
DROP TRIGGER Products_UPDATE; -- LINE 14
GO
CREATE TRIGGER Products_UPDATE
ON Products
INSTEAD OF UPDATE
AS
DECLARE @ProductID int, @CategoryID int, @ProductCode varchar, @ProductName varchar,
@Description varchar, @ListPrice money, @DiscountPercent money, @DateUpdated datetime
BEGIN
SELECT @ProductID = ProductID, @CategoryID = CategoryID, @ProductCode = ProductCode,
@ProductName = ProductName, @Description = Description, @ListPrice = ListPrice,
@DiscountPercent = DiscountPercent, @DateUpdated = GetDate()
FROM deleted;
INSERT INTO ProductsAudit
VALUES (@ProductCode, @CategoryID, @ProductCode, @ProductName, @ListPrice,
@DiscountPercent, @DateUpdated);
SELECT @ProductID = ProductID, @CategoryID = CategoryID, @ProductCode = ProductCode,
@ProductName = ProductName, @Description = Description, @ListPrice = ListPrice,
@DiscountPercent = DiscountPercent, @DateUpdated = GetDate()
FROM inserted;
UPDATE Products
SET CategoryID = @CategoryID, ProductCode = @ProductCode,
ProductName = @ProductName, Description = @Description,
ListPrice = @ListPrice, DiscountPercent = @DiscountPercent
WHERE ProductID = (SELECT ProductID FROM inserted)
END
I am confused a bit by (1) the location of the error and (2) the reason. I have looked over my defined data types and they all match.
Could someone offer a second set of eyes on the above and perhaps guide me towards a solution?
Thank you.This is an issue in this trigger. It will work for single record updates alone. Also for your requirement you dont need a INSTEAD OF TRIGGER at all.
You just need this
IF OBJECT_ID('Products_UPDATE') IS NOT NULL
DROP TRIGGER Products_UPDATE;
GO
CREATE TRIGGER Products_UPDATE
ON Products
AFTER UPDATE
AS
BEGIN
INSERT INTO ProductsAudit
SELECT ProductID,
CategoryID,
ProductCode,
ProductName,
ListPrice,
DiscountPercent,
GetDate()
FROM deleted;
END
Now, in your original posted code there was a typo ie you repeated the column ProductCode twice
I think one should be ProductID which is why you got error due to data mismatch (ProductID is int and ProductName is varchar)
see below modified version of your original code
IF OBJECT_ID('Products_UPDATE') IS NOT NULL
DROP TRIGGER Products_UPDATE; -- LINE 14
GO
CREATE TRIGGER Products_UPDATE
ON Products
INSTEAD OF UPDATE
AS
DECLARE @ProductID int, @CategoryID int, @ProductCode varchar, @ProductName varchar,
@Description varchar, @ListPrice money, @DiscountPercent money, @DateUpdated datetime
BEGIN
SELECT @ProductID = ProductID, @CategoryID = CategoryID, @ProductCode = ProductCode,
@ProductName = ProductName, @Description = Description, @ListPrice = ListPrice,
@DiscountPercent = DiscountPercent, @DateUpdated = GetDate()
FROM deleted;
INSERT INTO ProductsAudit
VALUES (@ProductID, @CategoryID, @ProductCode, @ProductName, @ListPrice,
@DiscountPercent, @DateUpdated);
SELECT @ProductID = ProductID, @CategoryID = CategoryID, @ProductCode = ProductCode,
@ProductName = ProductName, @Description = Description, @ListPrice = ListPrice,
@DiscountPercent = DiscountPercent, @DateUpdated = GetDate()
FROM inserted;
UPDATE Products
SET CategoryID = @CategoryID, ProductCode = @ProductCode,
ProductName = @ProductName, Description = @Description,
ListPrice = @ListPrice, DiscountPercent = @DiscountPercent
WHERE ProductID = (SELECT ProductID FROM inserted)
END
I would prefer doing it as former way though
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Easy Question: Illegal Start of Expression
This is a ridiculously easy question... but I am having trouble with it...
Anyway, here is the line of code that is giving me trouble:
jButtons = {{jButton1, jButton5, jButton9, jButton13},
{jButton2, jButton6, jButton10, jButton14},
{jButton3, jButton7, jButton11, jButton15},
{jButton4, jButton8, jButton12, jButton16}};
That's it. jButton1 through jButton16 are all jButton objects (for a GUI). jButtons is an array (4 by 4) of jButton. All are global variables, the buttons are all initilized (in fact, that was the problem I had before, and why I need to put this here: otherwise I get a null pointer exception).
Surprisingly, such a simple line of code causes TONS of errors to occur. To save space, {...} * 2 means that the exception occurs twice in a row, errors are separated by comma's.
{ Illegal Start of Expression, {Not a statement, ; required} * 2} * 4, Empty statement
A similar statement (int[] test = {{1,2,3},{4,5,6}};) works perfectly fine.
Please help, doing this will reduce the size of my code to about a third of the size of the code. And then I can laugh in the faces of those people who say that I write long, and in-efficient code! MWHAHAHAHAHAHA!!
However, I will keep at it, and Murphy's Law states I will find a solution 10 seconds after posting. If I do, I will edit this post, and tell you guys the answer ;)
[Edit]In case you are wondering... all my other code is correct. Here is the adjacent 3 methods:
private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {
ButtonClick(3,3);
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton10;
private javax.swing.JButton jButton11;
private javax.swing.JButton jButton12;
private javax.swing.JButton jButton13;
private javax.swing.JButton jButton14;
private javax.swing.JButton jButton15;
private javax.swing.JButton jButton16;
private javax.swing.JButton jButton17;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JLabel jLabel1;
// End of variables declaration
* @param args the command line arguments
public static void main(String args[])
jButtons = {{jButton1, jButton5, jButton9, jButton13},
{jButton2, jButton6, jButton10, jButton14},
{jButton3, jButton7, jButton11, jButton15},
{jButton4, jButton8, jButton12, jButton16}};
int[][] test = {{1,2,3},{4,5,6}};
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GameWindow().setVisible(true);
String[] row1 = {"1", "5", "9", "13"};
String[] row2 = {"2", "6", "10", "14"};
String[] row3 = {"3", "7", "11", "15"};
String[] row4 = {"4", "8", "12", ""};
String[][] labels = {row1, row2, row3, row4};
int blankX = 3;
int blankY = 3;
static javax.swing.JButton[][] jButtons;
private void DisableAll()
for (int looperX = 0; looperX < 4; looperX++)
for (int looperY = 0; looperY < 4; looperY++)
jButtons[looperX][looperY].setEnabled(false);
Edited by: circularSquare on Oct 13, 2008 5:49 PM
Edited by: circularSquare on Oct 13, 2008 5:52 PMYou can only initialise an array like that when you declare it at the same time. Otherwise you have to do as suggested above.
int[] numbers = {1,2,3,4}; //ok
int[] numbers;
numbers = {1,2,3,4}; // not ok -
Hi,
I have a file where fields are wrapped with ".
=========== file sample
"asdsa","asdsadasdas","1123"
"asdsa","asdsadasdas","1123"
"asdsa","asdsadasdas","1123"
"asdsa","asdsadasdas","1123"
==========
I am having a .net method to remove the wrap characters and write out a file without wrap characters.
======================
asdsa,asdsadasdas,1123
asdsa,asdsadasdas,1123
asdsa,asdsadasdas,1123
asdsa,asdsadasdas,1123
======================
the .net code is here.
========================================
public static string RemoveCharacter(string sFileName, char cRemoveChar)
object objLock = new object();
//VirtualStream objInputStream = null;
//VirtualStream objOutStream = null;
FileStream objInputFile = null, objOutFile = null;
lock(objLock)
try
objInputFile = new FileStream(sFileName, FileMode.Open);
//objInputStream = new VirtualStream(objInputFile);
objOutFile = new FileStream(sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString(), FileMode.Create);
//objOutStream = new VirtualStream(objOutFile);
int nByteRead;
while ((nByteRead = objInputFile.ReadByte()) != -1)
if (nByteRead != (int)cRemoveChar)
objOutFile.WriteByte((byte)nByteRead);
finally
objInputFile.Close();
objOutFile.Close();
return sFileName.Substring(0, sFileName.LastIndexOf('\\')) + "\\" + Guid.NewGuid().ToString();
==================================
however when I run the bulk load utility I get the error
=======================================
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 3 (NumberOfMultipleMatches).
==========================================
the bulk insert statement is as follows
=========================================
BULK INSERT Temp
FROM '<file name>' WITH
FIELDTERMINATOR = ','
, KEEPNULLS
==========================================
Does anybody know what is happening and what needs to be done ?
PLEASE HELP
Thanks in advance
VikramTo load that file with BULK INSERT, use this format file:
9.0
4
1 SQLCHAR 0 0 "\"" 0 "" ""
2 SQLCHAR 0 0 "\",\"" 1 col1 Latin1_General_CI_AS
3 SQLCHAR 0 0 "\",\"" 2 col2 Latin1_General_CI_AS
4 SQLCHAR 0 0 "\"\r\n" 3 col3 Latin1_General_CI_AS
Note that the format file defines four fields while the fileonly seems to have three. The format file defines an empty field before the first quote.
Or, since you already have a .NET program, use a stored procedure with table-valued parameter instead. I have an example of how to do this here:
http://www.sommarskog.se/arrays-in-sql-2008.html
Erland Sommarskog, SQL Server MVP, [email protected] -
Conversion from type 'CalculatedFieldWrapperImpl' to type 'Integer' is not valid._
Hi,
I'm using SSRS 2008 to create a relatively simple report with a stored procedure as the dataset. The SP runs fine (no errors) but when I try to run the report I get "Conversion from type 'CalculatedFieldWrapperImpl' to type 'Integer' is not valid. "
error message. The data type is declared as int in SQL. I'm using several other int fields in the report without a problem. Anyone familiar with this error? Thanks.
Robert BocconeHmm, my research also suggests multi-value parameters may be the cause, but you say there aren't any in the report. These sings can sometimes be generated automatically though, even if you haven't knowingly created one. You could try checking the .rdl
file directly (if you're using BIDS, just go to View > Code, otherwise load the report into wordpad or similar) and searching for the term 'Parameter' to see if there is anything there. Otherwise, I'm afraid I'm getting a bit lost for ideas
too.I work to UK time. If this post, or another, answers your question, please click the 'Mark as answer' button so others with the same problem can find a solution more easily. -
Return String from values in int array
Hi
I am very new to Java and have been asked to carry out the following task.
Returns a string version of counterGroups. For each
group it gives its number (1 more than its index) and (in
parentheses) the number of counters currently in that group.
Each is followed by two spaces. Thus if there are 3 groups
with 7, 9 and 11 counters the string returned is
"1(7) 2(9) 3(11) "
I have created an array of type int referenced by counterGroups. It stores values 7,9 and 11.
I have made a start on my method but I am struggling. Any help would be appreciated. Please see my method below to see how far I have got. It does not compile.
public String toStr()
String output1;
String temp;
String other;
for (int i=0; i<counterGroups.length(); i++)
int num1 = counterGroups;
output1 = String.valueOf(num1);
other = "(" + output1 + ")";
temp =
int num1 = counterGroups[0];
output1 = String.valueOf(num1);
return "(" + output1 + ")";
regards
PaulWhen you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.
Paste in the exact error message and clearly indicate which line it's complaining about. -
Easy question hopefully.....
I have an easy question but am having a mental block. How can I assign the value of 0.05 to restock? What I need to do is return a 5% restocking value added onto the item. Make sense?
//Type.java
public class Type extends Office // Start of public subclass Itemtype that stores office items color.
private String color; //get string name
private float restock; //get float value of restock
private float item; //get float value of total items
public Type(String color,float restock, float item)
{ // constructor to initialize the fields
this.color = color;
this.restock = restock;
this.item = item;
public float getRestock()
return (this.item * this.restock) + (this.item);
} //end public subclass TypeDon't crosspost. Too late this time, but don't do it again.
-
Dear all, greetings, I did not mean to offend anyone by typing all my texts in capital letters, I am just used to it and at my age (63) it is better and easier for my eyes to type all the texts in my messages in capital letters.I do apologize about it all. I can assure you that I do respect all of you more that you maight me thinking of. i have the same difficulties in typing in small letters like yours in reading texts in CAPITAL letters.......tant pis, c' est la vie
For web and computing experts I would like to remind them that all the peoples nowadays have the same needs (or hobbies if you wish) regarding the electronic devices, web, compouters, softwares and that sort of thing.
If I WERE not to have technical support because of my prefiously used capital letters in me text messages, I have to confess that next time I will be more carefull about the devices producers........ I live and always learn (SOCRATES, girasko, aei didaskomenos)
Two questions
1. I noticed on the you tube videos about the new ipad that the main icons are more than mine (i.e. the icon of facebook and a number or others are missing)
2. I would like to ask you to do me a favour, thanks for your patiene. Still I have not understood how (in which way, the pictures, transfered from my system or new taken by the ipad camera are uploaded directly to the FaceBook. I suppose that I will not have the same difficulties regarding the videos to both Facebook AND YoutTube. Thanks a lot for your patience with me, from now on I will be more carefull about posting messages to you referring to technical support
Constantinos
Athens, GreeceSome of the apps shown in adverts / videos have been downloaded from the App Store, they don't come pre-installed e.g. the Facebook app is a free download the app store : 'official' Facebook app.
To upload photos to Facebook you can use the above app - you can't, for example, use Safari on the iPad to upload content to sites.
Not sure whether any apps allow you to upload videos to YouTube (I don't use the site). -
*****Assignment Operator Question - String Operations*****
There's a lot of code here, but my question pertains to the italicized portion. I am assigning one StringObject to another. But when the assignment is tested with a System.out.println in the TestStringObject class, it doesn't look like the assignment has occurred properly. Even thought the string is reversed with the myObj.reverse() method, when the object is printed to the screen, it does not appear to be reversed. Is there really a problem with the way the assignment is occurring or am I misunderstanding the way assignment occurs in Java. By the way, the TestStringObject class must stay as is, but the StringObject code can be modified. Thanks!
class TestStringObject{
public static void main(String [] args){
StringObject myObj, yourObj;
myObj = new StringObject("Hello-World!!! Java/is/awesome.");
yourObj = new StringObject("a man a plan a canal panama");
myObj.stripCharacters("-!/.");
myObj.displayStringObject();
System.out.println();
myObj.reverse();
myObj.displayStringObject();
System.out.println();
yourObj.stripCharacters(" ");
System.out.print("yourObj = ");
yourObj.displayStringObject();
System.out.println();
myObj = new StringObject(yourObj.getStore());
myObj.reverse();
System.out.print("myObj = ");
myObj.displayStringObject();
System.out.println();
if(myObj.equals(yourObj))
System.out.println("they are equal");
else
System.out.println("they are not equal");
import java.lang.String.*;
class StringObject{
private String store;
private int storeLength;
public StringObject(String s){
//Creates a new StringObject by saving the string s in
//the instance variable store and its length in
//the instance variable storeLength.
store = new String(s);
storeLength = store.length();
public void displayStringObject(){
//Display the instance variable store.
System.out.println(store);
public void reverse(){
//Updates store to hold the reverse of its contents.
String reverseString = new String();
char reverseLetter;
for (int z = storeLength - 1; z > -1; --z){
reverseLetter = store.charAt(z);
reverseString = reverseString + reverseLetter;
store = reverseString;
public void stripCharacters(String stg){
//Update store to hold its contents after each of the
//characters in stg has been removed.
int tempLength = stg.length();
char newChar;
for (int i = 0; i < tempLength; i++){
newChar = stg.charAt(i);
stripACharacter(newChar);
storeLength = store.length();
public boolean equals(StringObject sObj){
//Determines if the store in sObj is identical to
//the store in the receiver without regard to case.
String newStore = sObj.store;
if (newStore.equalsIgnoreCase(store))
return true;
else
return false;
public String getStore(){
//Return the store to the caller.
return store;
private void stripACharacter(char ch){
//Update store to contain its contents after every occurrence
//of character ch has been removed.
String testString = new String();
char letter;
for (int x = 0; x < storeLength; x++){
letter = store.charAt(x);
if (letter != ch){
testString = testString + letter;
store = testString;
The Output:
D:\CMU>java TestStringObject
HelloWorld Javaisawesome
emosewasiavaJ dlroWolleH
yourObj = amanaplanacanalpanama
myObj = amanaplanacanalpanama
they are equalIt looks to me like your output is correct. What were you expecting when you compared a palindrome to its reverse?
I changed it to something that is not the same in both directions and got this output, which is also correct:HelloWorld Javaisawesome
emosewasiavaJ dlroWolleH
yourObj = abcdefg
myObj = gfedcba
they are not equal
Maybe you are looking for
-
Error: Internal Prising Error while using BAPI_PO_CREATE1
Hi Experts, I am creating PO from Contract (VA41/VA42) using BAPI_PO_CREATE1 in user exit MV45AFZZ - USEREXIT_SAVE_DOCUMENT_PREPARE. BAPI is returning the PO number and after coming out from BAPI. I am getting an popup message STOP - Internal Prising
-
[CS3][JS] How to get list of Actions and Action Groups
Does anyone know of a Javascript method for retrieving the list of Action Group names and Action names as an array? I'm trying to do a check that the requested Action Group and Action is available before starting a script. Thank you.
-
Mini iPad screen and system issues
Hi im a new mini ipad user and i want to seek your help on 2 things. 1) what do i need to do if the sceen of my ipad is blinking? I just bought it 2 weeks ago. 2) why is it that the system is crashing when you open 3 applications then suddenly it wi
-
My docking-speakers doesn´t work.
I have bought a Audio pro Porto Go. My Iphone 3gs OS4 connect with the speaker but the sound passes through the iphonespeakers. I can control the iphone with the remote, it charges but the sound doesn´t come out properly. I have restarted the iphone
-
Transaction in Weblogic 5.1 Server
Hi All, Can any one tell me How to set XA DataSource details in weblogic.properties file in weblogic 5.1 server. Thanx Ramana Murthy