 |
 |
When posting your question please:- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode HTML tags when pasting" checkbox before pasting anything inside the PRE block, and make sure "Ignore HTML tags in this message" check box is unchecked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question in one forum from another, unrelated forum (such as the lounge). It will be deleted.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-fou
|
|
|
|
 |
a very beginner question...
i'm a newbie in programming... just started java and read about packaging... i created i directory called firstproject and put a directory with one class inside of it and a FirstProject source file in the firstproject directory itself.
i made a class in that package directory that has a private string in it and tried to invoke from FirstProject source file but
getting compile error that the string is private...
i tried changing the string into protected or even public but still getting this error...
this is the class src file...
<pre lang="java">
package stickers;
public class Sticker
{
private String note;
Sticker(String note)
{
this.note = note;
}
public void displayNote()
{
System.out.println(note);
}
}
this is the FirstProject src file...
package firstproject;
import stickers.Sticker;
public class FirstProject
{
public static void main(String[] args)
{
Sticker sticker = new Sticker("hello sticky mehdi");
sticker.displayNote();
}
}
this is the actuall error:
error: Sticker(String) is not public in Sticker; cannot be accessed from outside package
|
|
|
|
 |
You need to make your constructor public so other packages can access it:
public class Sticker
{
private String note;
public Sticker(String note)
{
this.note = note;
}
I would recommend going to The Java Tutorials[^] and working through them.
|
|
|
|
 |
Hello there. I have managed to load and use c++ dll using JNI, in my java servlet (System.load). It works perfectly on first request I submit. But on subsequent requests, I get this weir d exception.
java.lang.UnsatisfiedLinkError: Native Library WEB-INF/lib/XXXXXX.dll already loaded in another classloader
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1525)
Here is my loading code
public void init(ServletConfig config) throws ServletException
{
super.init(config);
ServletContext context = getServletContext();
String sMathDllpath = context.getInitParameter("MathDLLPath");
System.load(sMathDllpath);
}
I studied this tomcat wiki link and implemented their solution, among others, but could not succeed.
How do I implement it successfully? Thnks for anything you share.
|
|
|
|
 |
You should declare it as a static action at class level like:
class ... {
static
{
System.loadLibrary("MathDLLPath");
}
}
That will ensure it is loaded when the class is first instantiated, but will only be loaded once.
|
|
|
|
 |
Richard MacCutchan wrote: You should declare it as a static action at class level like:
I tried this just now. This is what I have
public class MainServlet extends HttpServlet
{
static{
System.loadLibrary("MathDll");
}
......... }
And this is the exception I am getting
java.lang.UnsatisfiedLinkError: Native Library C:\Program Files\Java\jdk1.7.0_71\bin\MathDll.dll already loaded in another classloader
What am I doing wrong now?
|
|
|
|
 |
No idea, but it looks like you may have more than one call somewhere. Time to get the debugger out. Although, I have never used JNI in a servlet so it may be that there is something else happening.
|
|
|
|
 |
Hello, I wanted to create a launcher for a game (Minecraft), but then I had an idea, that if I read some source codes that it would make it easier for me to make it, so I went searching for a source code , and I found one, but then I was testing it if it's working or not, and it opened, but then when I pressed launch after seconds it says that it couldn't update or something, I'm gonna put the source code file if you could please help me I'll appreciate that.
SKMCLauncher-fourth[^]
The error is
The following information can be provided to the developer:
com.sk89q.skmcl.LauncherException: Something went wrong while trying to update.
at com.sk89q.skmcl.launch.LaunchWorker.update(LaunchWorker.java:105)
at com.sk89q.skmcl.launch.LaunchWorker.call(LaunchWorker.java:141)
at com.sk89q.skmcl.launch.LaunchWorker.call(LaunchWorker.java:44)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "downloads" (Class com.sk89q.skmcl.minecraft.model.Library), not marked as ignorable
at [Source: java.io.StringReader@6738ae66; line: 21, column: 27] (through reference chain: com.sk89q.skmcl.minecraft.model.ReleaseManifest["libraries"]->com.sk89q.skmcl.minecraft.model.Library["downloads"])
at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:217)
at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:194)
at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)
at org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299)
at org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:414)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
at com.sk89q.skmcl.util.HttpRequest$BufferedResponse.asJson(HttpRequest.java:470)
at com.sk89q.skmcl.minecraft.MinecraftUpdater.installGame(MinecraftUpdater.java:166)
at com.sk89q.skmcl.minecraft.MinecraftUpdater.call(MinecraftUpdater.java:129)
at com.sk89q.skmcl.minecraft.MinecraftUpdater.call(MinecraftUpdater.java:53)
at com.sk89q.skmcl.launch.LaunchWorker.update(LaunchWorker.java:101)
... 6 more
|
|
|
|
 |
Which area of Java has the greatest potential? Java security, web/mobile, telecommunications or data analytics?
|
|
|
|
 |
Which area of Java has the greatest potential? Java security, web/mobile, telecommunications or data analytics?
|
|
|
|
 |
None of us can foretell the future.
|
|
|
|
 |
Hi,
I have a Oracle DB in which all the information is stored and this information is been consumed by different teams and below is the two options i have to decide on :
1. Write a Stored procedure and give the stored procedure to the respective teams and they can call the stored procedure.
2. Write a stored procedure wrap it as an API and expose the API, different team will call the API exposed and API will in turn hit the SP and return the response to the team.
Like to know what is the PRON and CRONS with these options and what is the best possible solution to go with.
Thanks
|
|
|
|
|
 |
Hello there. I am trying to get rid of scriptlets. I attach an object from servlet and try to access it in JSTL. But the logs say that JSP can not find the properties of this object. Here is the servlet sample
request.setAttribute("student", student);
Here is the JSTL sample, with different combinations - all producing no result at all (how ever scriptlets do)
<c:set var="student" value='${requestScope.student}' scope="request" />
<input type='text' value='${student.FirstName}' /> <input type='text' value='${student.FirstName}' />
<input type='text' value='<c:out value='${student.FirstName}' />' /> <input type='text' value=<c:out value='${student.FirstName}' /> />
As you can see, I have tried different combinations but could not get and display value of request attribute using JSTL. What is wrong? Thanks for any input.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
 |
It is solved. Class was in default package. I put it in a package and import that Package.Class in JSP. works like a charm.
================
Hello there. I am attaching two variables with a HttpServletRequest request, an integer and an arraylist. After this when I forward request to a JSP, these casting issues arise. Here is the java servlet code
ArrayList<Employee> list_employees = m_objDbLayer.GetEmployeesAll();
int employee_count = list_employees.size();
request.setAttribute("employee_count", employee_count);
request.setAttribute("list_employees", list_employees);
RequestDispatcher dispatcher = request.getRequestDispatcher("/ViewEmployeesPage.jsp");
dispatcher.forward(request, response);
And here is the JSP code where I access these variables
<%@page import="java.util.ArrayList"%>
<%@page import="/WEB-INF/classes/Employee" %>
<!-- all the starting HTML tags here-->
<%
int employee_count= (int)request.getAttribute("employee_count");
out.println("Total Employees: " + employee_count);
ArrayList<Employee> list_users =new ArrayList<Employee>();
list_users = (ArrayList<Employee>)request.getAttribute("list_employees");
%>
I get these exceptions in server log
1- Cannot cast from Object to int
2- Employee cannot be resolved to a type
As you can see I am importing Employee class in JSP, what is wrong? Why it can not resolve Employee and convert from object to int? Thanks for any input.
modified 26-Aug-16 6:32am.
|
|
|
|
 |
Hi All,
I am getting exception as Query result does not exist after calling the mehod QueryResults in drools.
qResults = kSession.getQueryResults ("results");
Is there any drools expert on coderanch who can help me to resolve the exception.
Please let me know if you need additional information.
Thanks,
|
|
|
|
 |
The message is telling you what the problem is. The query named "results" cannot be found. Check your system settings, configuration etc, or wherever the queries are stored. See also https://docs.jboss.org/jbpm/v5.1/javadocs/org/drools/runtime/rule/WorkingMemory.html#getQueryResults(java.lang.String, java.lang.Object...).
|
|
|
|
 |
i had wrote a code to connect to remote oracle data & execute query to find a task whether to check running or not...
I am getting the output in the console, but i need to print the console output to a file.. eg: while(re.next){ executeing the query(select * from product_inventory_task)
acutally code connects to mutiple server & get the result.
while printing the result to text file ,it prints only the last value stored query reslut
|
|
|
|
 |
Member 11427657 wrote: while printing the result to text file ,it prints only the last value stored query reslut So there is obviously a bug in your code. But since we cannot see your code we have no idea what that bug may be. I already gave you a suggestion to your previous post on this issue, at Re: how to write the console output to text file? - Java Discussion Boards[^]. Did you follow the link I provided?
|
|
|
|
|
 |
I am a Java developer and I love Java to the core. I always wanted to learn the skills for creating web applications but never really got the time for it. But, lately I wanted to challenge myself to learn and create a web application. Now, here is the dilemma:-
I did some research before actually starting to develop the web application. I have narrowed my option down to two:- a. Use Java (learn JSP and servlets) - my heart is biased towards this approach. b. Use Python and Django framework - my mind is biased towards this approach. Now, I did some research on the Django framework and found a lot of positive reviews whereas I also found mixed reactions on the web regarding the use of Java for web applications. Consider me completely naive to the world of web applications as this will be my first time and it's nothing industry related or work. It's just a tool and knowledge that I want to learn.
I went on and followed some tutorials on Django but honestly, I din't really enjoy it that much but I am still open to giving it a shot.
So, my question is Will I be at a disadvantage if I create web applications using Java using the JSP and Servlets or should i follow the new trend of using Django and Python? Where could I miss the edge if I use Java over Python?
|
|
|
|
 |
Rebecca1995 wrote: Will I be at a disadvantage if There is no way to answer such a question, beyond saying go with what you find interesting and enjoy. If you are looking to develop professional skills, then you need to research what skills are in demand where you live.
|
|
|
|
 |
i think one should follow his heart instead of running behind trend.If u listen to your heart u will be more successful because u love what u r doing.Talking about java... It a wonderful language loved by many.and it will never face any crises for sure.so go for java..get mastery over it and concure the web world. to start with i will suggest
1. Get perfect in syntax
2. Create some sample project not so bulky but small
3. try to improve last done project by adding something new
4. imagine things around you which can be module in servlets and jsp format
5.try to find out market for your work done this will give you financial benefit and so you will get motivated to work harder
finally i wish almighty to give all the success
|
|
|
|
|
 |
Thanks for your advice,think i should also do the same by mastering one programming language for now.I think i will opt for java
|
|
|
|
 |
Rebecca1995 wrote: web application. ... (learn JSP and servlets) -
I will note that I have been doing this for a while and it does depend on what you mean by "web application" but I haven't seen anyone using JSP and servlets for quite some time.
In terms of general java expertise the idioms applicable to actually using those will apply to other stuff (quite a bit actually in the modern world) so you could do that. But be careful to learn why each of those has different semantics rather than just learning how to implement each. Or more specifically learn how class loading works in depth.
|
|
|
|
 |
I'm studing Android language in Android Studio. I know that Anrdoid language is derived by Java, but I desired to review my knowledge on Java programming. So, how is Android libraries similar to Java? Can I find in Java packages and programming-techniques the same components like: Broad Cast Reciver, Intent, Intent Filter and so on?
|
|
|
|
 |
Classes unique to Android are not necessarily in mainstream Java since they have no relevance outside the Android framework.
|
|
|
|
 |
Thank you for repaly. So I can't find in Java "component" or resources like Intent, BroadCast Receiver and so on... Isn't it? How can I replace those (i.e. event, event handler, back ground task)?
|
|
|
|
|
 |
i doing a jdbc connectivity to connect to a remote oracle databases & running a query & the query result are show in console.
OUTPUT: backup Taskintiated done for 1st. backup Taskintiated done for 2st.
I want this console output to a text file..
|
|
|
|
|
 |
public class sampl{ private static final boolean Null = false; static String store = null; static String ip = null; static String port= null; static String username = null; static String password = null; static String sid = null; static String get = null; static String s; static String v="success"; static String sa = null; static String fullstr = null; String[] spl= null; int i = 0; public static void main(String[] args) throws FileNotFoundException { {
String csvFile = "C:\\purge_test\\sam.csv"; BufferedReader br = null; String line =null; String cvsSplitBy = ","; String[] spl= null; String detail[]=null; try {
br = new BufferedReader(new FileReader(csvFile)); // System.out.println("*****"); while ( (line = br.readLine() ) != null) { // System.out.println("inside"); // use comma as separator detail = line.split(cvsSplitBy); // System.out.println("server ip = " + detail[1] +"\tport = " + detail[2] + "\tUsername"+ detail[3]+"\tPassword = "+ detail[4]+"\tSID = "+ detail[5]); try{ store =detail[0]; ip = detail[1]; port= detail[2]; username = detail[3]; password = detail[4]; sid = detail[5]; int po = Integer.parseInt(port); //step1 load the driver class Class.forName("oracle.jdbc.driver.OracleDriver"); String a = "jdbc:oracle:thin:@"+ip+":"+po+":"+sid; // System.out.println("string a:" + a); // System.out.println("usrname:"+username); //.out.println("pswd:"+password); //step2 create the connection object Connection con=DriverManager.getConnection(a,username,password); // Connection con=DriverManager.getConnection( // "jdbc:oracle:thin:@172.26.64.50:1521:xe","OATXPRESS","Ckpoatorapw1234"); // // //System.out.println("qqqq"); //Connection con=DriverManager.getConnection("a",username,password); //step3 create the statement object Statement stmt=con.createStatement(); // System.out.println("rrrr"); // java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); //step4 execute query ResultSet rs=stmt.executeQuery("select TASK_NAME,to_char(START_TIME,'DD-MON-YYYY HH24:MI:SS') as RUN_TIME,case when count(*) > 0 then 'Task Initiated' else 'Task Not Initiated' end as \"TASK_Status\" from TMS_TASK_LOG where (TASK_NAME='purge_database' or TASK_NAME='db_stats_collection') and to_char(START_TIME, 'DD-MON-YYYY')=TO_CHAR(SYSDATE, 'DD-MON-YYYY') group by TASK_NAME,START_TIME "); //File file = new File("C:/purge_test/tr.txt"); // ResultSet rs=stmt.executeQuery("select TMS_TASK_LOG_ID,TASK_NAME,START_TIME,STATUS from TMS_TASK_LOG where TASK_NAME = 'purge_database' AND ROWNUM < = 1 order by 1 desc"); if(rs.next()) { System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "); /*System.out.println(rs.getString(1)+" "); System.out.println(rs.getString(2)+" "); System.out.println(rs.getString(3)+" "); //System.out.println(rs.getString(4)+" "); Date d = new Date(); System.out.println("date "+d);*/ String fullstr =rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "; System.out.println("**********"+fullstr); //__________________________ FileWriter fw = new FileWriter("C:/purge_test/foooooo.txt"); for (int i = 0; i < 10; i++) { fw.write("something:\t"+ fullstr); } fw.close();
System.out.println("****00000******"+fullstr); }
System.out.println("Done for store :"+store); //step5 close the connection object con.close(); }catch(Exception e){ System.out.println(e);} }
} catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close();
} catch (IOException e) { e.printStackTrace(); } } }
}
|
|
|
|
 |
OUTPUT : purge_database 16-AUG-2016 04:00:08 Task Initiated **********purge_database 16-AUG-2016 04:00:08 Task Initiated ****00000******purge_database 16-AUG-2016 04:00:08 Task Initiated Done for store :Test purge_database 16-AUG-2016 04:00:15 Task Initiated **********purge_database 16-AUG-2016 04:00:15 Task Initiated ****00000******purge_database 16-AUG-2016 04:00:15 Task Initiated Done for store :store
This to be printed in a text file...
while running the above code... only value of fullstr purge_database 16-AUG-2016 04:00:15 Task Initiated **********purge_database 16-AUG-2016 04:00:15 Task Initiated
is printed to a text file...
i want all the output of console to be writed in a text file
|
|
|
|
 |
~You already posted this in QA; please do not post the same question in multiple forums.
|
|
|
|
 |
Looking at the time-stamps, the QA question is the repost. This forum post is a repost of the one immediately below, which appears to be the original.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
 |
Yes, I noticed that after I posted my comment. Either way he's trying the scatter gun approach.
|
|
|
|
 |
<pre lang="C#">public class sampl{ private static final boolean Null = false; static String store = null; static String ip = null; static String port= null; static String username = null; static String password = null; static String sid = null; static String get = null; static String s; static String v="success"; static String sa = null; static String fullstr = null; String[] spl= null; int i = 0; public static void main(String[] args) throws FileNotFoundException { {
String csvFile = "C:\\purge_test\\sam.csv"; BufferedReader br = null; String line =null; String cvsSplitBy = ","; String[] spl= null; String detail[]=null; try {
br = new BufferedReader(new FileReader(csvFile)); // System.out.println("*****"); while ( (line = br.readLine() ) != null) { // System.out.println("inside"); // use comma as separator detail = line.split(cvsSplitBy); // System.out.println("server ip = " + detail[1] +"\tport = " + detail[2] + "\tUsername"+ detail[3]+"\tPassword = "+ detail[4]+"\tSID = "+ detail[5]); try{ store =detail[0]; ip = detail[1]; port= detail[2]; username = detail[3]; password = detail[4]; sid = detail[5]; int po = Integer.parseInt(port); //step1 load the driver class Class.forName("oracle.jdbc.driver.OracleDriver"); String a = "jdbc:oracle:thin:@"+ip+":"+po+":"+sid; // System.out.println("string a:" + a); // System.out.println("usrname:"+username); //.out.println("pswd:"+password); //step2 create the connection object Connection con=DriverManager.getConnection(a,username,password); // Connection con=DriverManager.getConnection( // "jdbc:oracle:thin:@172.26.64.50:1521:xe","OATXPRESS","Ckpoatorapw1234"); // // //System.out.println("qqqq"); //Connection con=DriverManager.getConnection("a",username,password); //step3 create the statement object Statement stmt=con.createStatement(); // System.out.println("rrrr"); // java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); //step4 execute query ResultSet rs=stmt.executeQuery("select TASK_NAME,to_char(START_TIME,'DD-MON-YYYY HH24:MI:SS') as RUN_TIME,case when count(*) > 0 then 'Task Initiated' else 'Task Not Initiated' end as \"TASK_Status\" from TMS_TASK_LOG where (TASK_NAME='purge_database' or TASK_NAME='db_stats_collection') and to_char(START_TIME, 'DD-MON-YYYY')=TO_CHAR(SYSDATE, 'DD-MON-YYYY') group by TASK_NAME,START_TIME "); //File file = new File("C:/purge_test/tr.txt"); // ResultSet rs=stmt.executeQuery("select TMS_TASK_LOG_ID,TASK_NAME,START_TIME,STATUS from TMS_TASK_LOG where TASK_NAME = 'purge_database' AND ROWNUM < = 1 order by 1 desc"); if(rs.next()) { System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "); /*System.out.println(rs.getString(1)+" "); System.out.println(rs.getString(2)+" "); System.out.println(rs.getString(3)+" "); //System.out.println(rs.getString(4)+" "); Date d = new Date(); System.out.println("date "+d);*/ String fullstr =rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "; System.out.println("**********"+fullstr); //__________________________ FileWriter fw = new FileWriter("C:/purge_test/foooooo.txt"); for (int i = 0; i < 10; i++) { fw.write("something:\t"+ fullstr); } fw.close(); System.out.println("****00000******"+fullstr); }
System.out.println("Done for store :"+store); //step5 close the connection object con.close(); }catch(Exception e){ System.out.println(e);} }
} catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (br != null) { try { br.close();
} catch (IOException e) { e.printStackTrace(); } } }
} }}//____________________________________________________</pre>
|
|
|
|
 |
Hello there. I am trying to insert record into MySQL table. Record gets inserted but I am getting this weird exception. Here is my code
Class.forName(JDBC_DRIVER);
m_MySqlConnection = DriverManager.getConnection(DB_URL, USER, PASS);
PreparedStatement add_emp_prepstmt = m_MySqlConnection.prepareStatement("INSERT INTO EmployeeDetails VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
add_emp_prepstmt.setString(1, emp.EmployeeId);
add_emp_prepstmt.setString(2, emp.Password);
add_emp_prepstmt.setString(3, emp.FirstName);
add_emp_prepstmt.setString(4, emp.SurName);
add_emp_prepstmt.setInt(5, emp.Age);
add_emp_prepstmt.setInt(6, emp_sex_id);
add_emp_prepstmt.setString(7, emp.Address);
add_emp_prepstmt.setString(8, emp.City);
add_emp_prepstmt.setInt(9, emp_maritalstatus_id);
add_emp_prepstmt.setString(10, emp.EmailId);
add_emp_prepstmt.setInt(11, emp_type_id);
add_emp_prepstmt.setInt(12, emp_department_id);
add_emp_prepstmt.setString(13, emp.Designation);
add_emp_prepstmt.setDouble(14, emp.Salary);
add_emp_prepstmt.setString(15, emp.NTN);
add_emp_prepstmt.setDouble(16, emp.TaxPercent);
add_emp_prepstmt.executeUpdate();
And following is the exception showing
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'muzammil-XYZ-1235' for key 'PRIMARY'
with tons of locations afterwards. Last line of code snippet shows exact exception location. Agaiiiin, record gets inserted. What could be wrong?? Thanks.
|
|
|
|
 |
Not weird at all.
Django_Untaken wrote: What could be wrong??
SQL do not allow duplicate values in a column that is primary key.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
 |
Yes. But I delete all the rows from table, before doing anything. It inserts the row and then gives this exception.
|
|
|
|
 |
Check that you don't try to insert 2 times the same key
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
 |
Thanks to richard's pointer...it is solved.
=========================
Hello there. I am trying to connect to mysql database from my basic servlet. As you can see, I reach the servlet but facing this exception when trying to load the MySQL driver.
String JDBC_DRIVER="com.mysql.jdbc.Driver";
String DB_URL="jdbc:mysql://localhost/testdb";
Class.forName(JDBC_DRIVER);
I use command line to compile this servlet with all possible JARs.
javac -classpath ".;path/to/servlet-api.jar;path/to/tomcat-jdbc.jar;path/to/jasper.jar;path/to/mysql-connector-java-5.1.33-bin.jar" FormDbServlet.java
When I try to get values on my HTML page from servlet, I reach the doGet() method but there I get the said exception. What could be wrong? Thanks for any pointer.
modified 5-Aug-16 9:37am.
|
|
|
|
|
 |
Hello all,
This is the circumstance. I am an QA Automation Engineer and right now I am being charged with setting up our CI framework in Jenkins but right now I am having issues with Maven. I am getting this error below when I try to run the mvn test command. However the tests work flawlessly in eclipse when run as maven test.
T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configur
ator@3830f1c0
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configur
ator@bd8db5a
Tests run: 16, Failures: 1, Errors: 0, Skipped: 14, Time elapsed: 0.66 sec <<< F
AILURE!
beforeTest(fcstestingsuite.fsnrgn.LoginTest) Time elapsed: 0.442 sec <<< FAILU
RE!
java.lang.IllegalStateException: The path to the driver executable must be set b
y the webdriver.chrome.driver system property; for more information, see https:/
/github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be dow
nloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:19
9)
at org.openqa.selenium.remote.service.DriverService.findExecutable(Drive
rService.java:109)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDrive
rService.java:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExe
cutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(Driver
Service.java:296)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(C
hromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
at fcstestingsuite.fsnrgn.LoginTest.beforeTest(LoginTest.java:54)
Results :
Failed tests: beforeTest(fcstestingsuite.fsnrgn.LoginTest): The path to the dr
iver executable must be set by the webdriver.chrome.driver system property; for
more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver.
The latest version can be downloaded from http://chromedriver.storage.googleapis
.com/index.html
Tests run: 16, Failures: 1, Errors: 0, Skipped:
14
As you can see it is related to my chrome system property/path. In my project I have a test package and page object package. I set my chrome system property in the object class and import that class into the test class which works fine in eclipse. I'm not quite sure why Maven is having an issue with this.
Sample code below
Page Class
package pageobjectfactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.FindBy;
import org.testng.Assert;
public class Ourfsnlogin {
@FindBy(id="ctl00_ContentPlaceHolder1_tbxUname")
WebElement login;
@FindBy(id="ctl00_ContentPlaceHolder1_tbxPword")
WebElement password;
@FindBy(id="ctl00_ContentPlaceHolder1_btnSubmit")
WebElement submit;
@FindBy(name="ctl00$ContentPlaceHolder1$rptAccounts$ctl01$AccountSwitch")
WebElement PETSMARTUS;
@FindBy(name="ctl00$ContentPlaceHolder1$rptAccounts$ctl02$AccountSwitch")
WebElement PETSMARTCAD;
@FindBy(name="ctl00$ContentPlaceHolder1$rptAccounts$ctl03$AccountSwitch")
WebElement PETSMARTPR;
@FindBy(id="ctl00_lblTopLogin")
WebElement PETSMARTUSASSERT;
@FindBy(id="ctl00_lblTopLogin")
WebElement PETSMARTCAASSERT;
@FindBy(id="ctl00_lblTopLogin")
WebElement PETSMARTPRASSERT;
@FindBy(id="ctl00_Menu1_16")
WebElement LogoutButton;
public static WebDriver driver;
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\dmohamed\\Documents\\Testing Environment\\Testing Environment\\Web Drivers\\chromedriver_win32 (1)\\chromedriver.exe");
WebDriver chromedriver = null; new ChromeDriver();
driver= chromedriver;
}
public void sendUserName(String strUsername){
login.sendKeys("ebluth");}
public void sendUserNameServiceCenter(String strUsername){
login.sendKeys("servicecenter");}
public void sendUserNameSP(String strUsername){
login.sendKeys("4328701");
}
public void sendPassword(String strPassword){
password.sendKeys("password");}
public void clicksubmit(){
submit.click();}
public void USAssertion(){
PETSMARTUS.isEnabled();
}
public void CAAssertion(){
PETSMARTCAD.isEnabled();}
public void PRAssertion(){
PETSMARTPR.isEnabled();}
public void USclick(){
PETSMARTUS.click();
}
public void CAclick(){
PETSMARTCAD.click();}
public void PRclick(){
PETSMARTPR.click();}
public void USPageValidation(){
Assert.assertTrue(PETSMARTUSASSERT.getText().contains("PETM-US"), "Incorrect Page [US,CA,PR]");
}
public void PRPageValidation(){
Assert.assertTrue(PETSMARTPRASSERT.getText().contains("PETM-PR"),"Incorrect Page [US,CA,PR]");
}
public void CAPageValidation(){
Assert.assertTrue(PETSMARTCAASSERT.getText().contains("PETM-CN"),"Incorrect Page [US,CA,PR]");
}
public void Logout (){
LogoutButton.click();
}}
Test Class
package fcstestingsuite.fsnrgn;
import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import pageobjectfactory.Ourfsnlogin;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;
public class LoginTest {
static WebDriver driver;
Ourfsnlogin LoginPage;
@Test (priority=1)
public void USPageTest() {
LoginPage.sendUserName("ebluth");
LoginPage.sendPassword("password");
LoginPage.clicksubmit();
LoginPage.USclick();
LoginPage.USPageValidation();
}
@Test(priority=2)
public void CAPageTest(){
LoginPage.sendUserName("ebluth");
LoginPage.sendPassword("password");
LoginPage.clicksubmit();
LoginPage.CAclick();
LoginPage.CAPageValidation();
}
@Test (priority=3)
public void PRPageTest(){
LoginPage.sendUserName("ebluth");
LoginPage.sendPassword("password");
LoginPage.clicksubmit();
LoginPage.PRclick();
LoginPage.PRPageValidation();
}
@AfterMethod
public void aftermethod(){
LoginPage.Logout();
}
@BeforeTest
public void beforeTest() {
Ourfsnlogin.driver=new ChromeDriver();
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 20), this);
Ourfsnlogin.driver.get("http://www.ourfsn.com/myfsn");
LoginPage= PageFactory.initElements(Ourfsnlogin.driver, Ourfsnlogin.class);
}
@AfterTest
public void afterTest() {
Ourfsnlogin.driver.quit();
}
}
Any help would be greatly appreciated
|
|
|
|
 |
Remove both Jenkins and Eclipse from the process.
Validate that maven and java are installed on the work box (again neither of those have anything to do with Jenkins nor Eclipse.)
Create new directory.
Extract the entire source tree (repository, whatever) into that new directory.
Open a console window and cd to that new directory.
Run maven from there.
If the above fails, I suspect it will, then development, not QA/Test is responsible for fixing the contents of source control so that it runs. That however is a management problem not a technical problem.
I suspect the above will still fail. And it indicates that the unit tests are not set up correctly in that they are relying on something in eclipse. You probably have to add one or more configuration files.
It is quite possible that the configuration already exists somewhere but it is not accessible in the context in which the tests run. As a suggestion, and only a suggestion, the needed configuration files might be found in the 'primary' directory (wherever the delivered application actually starts to run) and they need to be moved and perhaps even modified into the parent directory where the tests are very likely into '.../src/test/resources' but other locations might be possible as well.
|
|
|
|
 |
I try to read TTL file and make traversing get subject, predict and object.
the program compile successfully but no output as a result of entering in an infinite call as I understood. any suggestion for help
package new_try;
import com.hp.hpl.jena.graph.Triple;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.lang.PipedRDFIterator;
import org.apache.jena.riot.lang.PipedRDFStream;
import org.apache.jena.riot.lang.PipedTriplesStream;
public class New_try {
public static void main(String[] args) throws FileNotFoundException {
final String filename = "E:\\yagoTransitiveType.ttl";
System.out.println(filename);
System.out.println("Hello1");
PipedRDFIterator<Triple> iter = new PipedRDFIterator<>();
System.out.println("Hello2");
final PipedRDFStream<Triple> inputStream = new PipedTriplesStream(iter);
System.out.println("Hello3");
ExecutorService executor = Executors.newSingleThreadExecutor();
System.out.println("Hello4");
Runnable parser;
parser = new Runnable() {
@Override
public void run() {
System.out.println(filename);
RDFDataMgr.parse(inputStream, filename);
System.out.println("Hello6");
}
};
executor.submit(parser);
while (iter.hasNext()) {
Triple next = iter.next();
System.out.println("Subject: "+next.getSubject());
System.out.println("Object: "+next.getObject());
System.out.println("Predicate: "+next.getPredicate());
System.out.println("\n");
}
}
}
|
|
|
|
|
 |
i have .jar file of my code and i want to convert it into .exe or standalone file which can be run on my of windows system without java installation. please guide me how i can do this. i had tried JSmooth 0.9.9-7 and JexePack . but there exe needs java installation.
|
|
|
|