Today I found the same http request to the backend api server, sometimes it could fetch the article, sometimes it could not fetch the article, this is my code:
Article article = articleMapper.selectByPrimaryKey(id);
and this is the code generate automaticlly using MyBatis Generator:
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
<!--
WARNING - #mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
from article
where id = #{id,jdbcType=BIGINT}
</select>
the same http request, with the same article id. I do not know where is going wrong.My PostgreSQL version is 13. And this is my auto generate xml config:
<table tableName="article"
enableCountByExample="true"
enableUpdateByExample="true"
enableDeleteByExample="true"
enableSelectByExample="true"
selectByExampleQueryId="true">
<generatedKey column="ID" sqlStatement="JDBC" identity="true" />
</table>
any clue to figure out what wrong with the code? I am a newbie about PostgreSQL as backend database.
Does the article with the id you're querying for exist? Yes, I am sure the ID exists.
Could there be concurrent modifications? No, It is impossible. I will never edit the article after write into database. No transactions,The article is an old article.
Related
I referred to Java MVC, and I understood the following.(please correct me if I'm wrong)
M->Model(It is a Java Bean)
V->View(JSP/HTML)
C->Controller(Servlet)
Here when going through Java Beans in JDBC there are getters and setters, I want to know if this is all the columns from my DB, for example, I've 10 Columns, Do I need to do a Getters and Setters for all the 10 Columns?
Should I write my JDBC code in Servlet or Bean?
In my JSP I've two textboxes that fetch data from Database Columns. for that I use to do something like below (Just for Demonstration sake).
`
<table>
<tr>
<td>
<input type="text" value="<%=i%>" name="id1" id="id1">
</td>
<td>
<center>
<input type="text" value="<%=rs.getString("DBID")%>" readonly="readonly" id="abc<%=i%>" name="abc<%=i%>" size="100">
</center>
</td>
<td>
<input type="text" value="<%=i%>" name="id2" id="id2">
</td>
<td>
<center>
<input type="text" value="<%=rs.getString("description")%>" readonly="readonly" id="ab<%=i%>" name="ab<%=i%>" size="100">
</center>
</td>
</tr>
</table>
`
Here I'm fetching content from database and putting it in 2 textboxes.
How can I do it using MVC approach?
1.Here when going through Java Beans in JDBC there are getters and setters, I want to know if this is all the columns from my DB, for example, I've 10 Columns, Do I need to do a Getters and Setters for all the 10 Columns?
Yes you need 10 properties with the getter and setter.
2.Should I write my JDBC code in Servlet or Bean?
The JDBC code should be in a service which is called from the controller or in the controller itself.
3.In my JSP I've two textboxes that fetch data from Database Columns. for that i use to do something like below(Just for Demonstration sake).
You have to call the getter of the bean for the property you need.
You can find good tutorials in the web.
Please do more study to understand for e.g. http://howtodoinjava.com/2015/02/05/spring-mvc-hello-world-example/
But i ll try to answer ur questions
1) Here when going through Java Beans in JDBC there are getters and setters, I want to know if this is all the columns from my DB, for example, I've 10 Columns, Do I need to do a Getters and Setters for all the 10 Columns?
-> A Java bean need not have "all" the columns, instead bean should reflect truly which fields (whether columns in DB tables or computed ones) are required at the "view" (or calling business logic).
2) Should I write my JDBC code in Servlet or Bean?
-> JDBC code can be put into a separate LAYER - read more about DAO and layered architectures. So a single controller class receives an event (request) and then call the appropriate "manager" class which know what bunisess action is requried. It can call other manager classes which intern can call DB layer (DAO will help here)
for e.g. suppose controller receives request to create Order -->
Controller.invoke(Request reqCreateOrder) --> CreateOrderHandler.execute(OrderBean ob) ---> OrderDao.create(OrderVO) ---> [insert query]
3) In my JSP I've two textboxes that fetch data from Database Columns. for that i use to do something like below(Just for Demonstration sake).
--> similarly for fetch as well
Controller.invoke(Request reqFetchOrder)
--> FetchOrderHandler.execute(OrderBean bean) ---> OrderDao.fetch(OrderBean bean) ---> [select query]
--> FetchOrderView.render(OrderVO bean) --> invokes JSP !!
MVC is just a paradygm. In real world you may have much more layers :
view (JSP) (the less possible scriptlet here)
front-controller (provided by a framework such as Spring MVC or Struts)
controller (provided by programmer) : processes request parameters, call next layer and forwards to a view
service : implementation of business rules <= here should be the intelligence
persistence (JDBC will come here, but you could have ORM such as Hibernate or JPA)
Object model (beans) go through all those layers.
It would be too long for a SO answer to explain all that so :
search on google and wikipedia for MVC and MVC2 patterns
read tutorials (Struts, Spring, Hibernate ...)
discuss with fellows that already used them => not to be done in SO
choose an architecture with or without framework (*)
try it and than ask precise question here if needed
(*) Even without framework try to separate view (JSP) - controller (servlet) - service - persistence
What is the difference between delta import and full import in ApacheSolr?
What are all the naming conventions to be followed while writing deltaImportQuery and deltaQuery ( ID, TXT_ID etc), any references or tutorial explaining in detail about differences/relations between deltaImportQuery and deltaQuery, Like what it is and what it does etc, How to write deltaImportQuery and deltaQuery ?
How to configure multiple entities in one document, Suppose if there are three tables in database like T1, T2, T3, Then in schema.xml how to configure this, issue with only one <uniquekey>somename</uniquekey> been considered for each schema.xml file?
How to parse BLOB type input from mysql, following convert ( column_name using utf8 ) as alias_name solves this but what is the right convention ,some other methods are also available like using TikaEntityProcessor/ writing custom BLOBTRANSFORMERS etc ?
Just like ORM any concepts explaining how to denormalize and outline an Apache Solr document , Any showcase project including all use cases and features ?
How to configure entities like this in data-config.xml?
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/solrdemo" user="root" password="123" batchSize='1' />
<document name="user">
<entity name ="user1" query = "SELECT * FROM user1">
<field column='id' name='id1' />
</entity>
<entity name ="user2" query = "SELECT * FROM user2">
<field column='id' name='id2' />
</entity>
<entity name ="user3" query = "SELECT * FROM user3">
<field column='id' name='id3' />
</entity>
</document>
</dataConfig>
When the above kind of configuration is done then in schema.xml which id should be configured into <uniquekey></uniquekey> ?
The result of above configuration is
Indexing completed. Added/Updated: 2,866 documents. Deleted 0 documents. (Duration: 03s)
Indexing is successfully completed but 0 documents added / updated , How to resolve this issue ?
Overall any references available for proper conventions and configurations to work with Apache Solr?
I have been using JSTL to fetch values from my database and display it in my jsp page using a similar code as shown below.
<sql:setDataSource
var="myDS"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mydb"
user="root" password="secret"
/>
<sql:query var="list_users" dataSource="${myDS}">
SELECT * FROM users;
</sql:query>
<c:forEach var="user" items="${listUsers.rows}">
<c:out value="${user.name}" />
<c:out value="${user.email}" />
<c:out value="${user.profession}" />
</c:forEach>
My team leader advised me that it is not a good practice to put queries in the jsp page directly. Since there is a database name and username and password in this code I'm not sure if this code implements proper security. I would like to know your thoughts on the matter, and if there is any alternative to do this using JSTL itself.
Since JSTL is executed on server side, there's no security hole because the query cannot be seen by clients of the application. There are other problems with this approach:
The query is not reusable. If you need it in other pages, you will need to repeat the query. When you have simple queries like this one you cannot check the problem, but this arises with more complex statements that needs parameters as well.
You're creating a connection manually per page! This will slow your application. Use a proper datasource for a database connection pool configured as a resource or programatically (C3PO or BoneCP, for example)
Move all your database code into proper Data Access Layer classes. And use <sql> for JSTL for learning purposes only, not for real world applications.
More info:
How to use JSTL sql tag
Retrieve values from JDBC and use JSTL tags to call the methods
Should a database connection stay open all the time or only be opened when needed?
You should really do your query in your java class, not in the jsp, like your team leader advised.
On the security side it doesn't really matter, all the code is available on the server, jsp or java. The sql tag shouldn't output that information in the generated page.
But really the question is more about the right use of the technologies:
jsp is used as a template, it should take data and show them to the end user. Some basic operation can be done life looping on data list or formating data, but this should be only specific to the view you want to make
java controler is used to recuperate data and configure the view as needed like which jsp to use and which data to send in that jsp
I have changed the code of Orbeon Form Builder to add a new input field in dialog-form-settings.xbl:
<xf:input ref="category" id="fb-category-input" xxf:autocomplete="off">
<xf:label>Category</xf:label>
<xf:hint>input Category</xf:hint>
</xf:input>
<!-- Dispatch event with result -->
<xf:dispatch name="fb-update-metadata" targetid="fb-dialog-form-settings">
<xf:property name="app" value="instance()/app"/>
<xf:property name="form" value="instance()/form"/>
<!-- Add By Haibpl -->
<xf:property name="category" value="instance()/category"/>
<!-- End Add -->
<xf:property name="title" value="instance()/title"/>
<xf:property name="description" value="instance()/description"/>
<xf:property name="logo" value="instance()/logo"/>
<xf:property name="mode" value="instance()/mode"/>
</xf:dispatch>
In crud.xpl, how can i get value of category like app (/request/app)?
My recommendation most likely won't be what you're looking for, but here it is anyway: try to avoid making changes to Form Builder and Form Runner. Those changes can be hard to port to new versions of Orbeon Forms, make it hard to upgrade, and then, if you are stuck with an older version, to get support for it.
Also, while you can get help from Orbeon for these type of customizations under a Dev Support subscription, customization are not covered by PE subscriptions, and you won't get much help in the community either, as this isn't something we'd like to encourage.
So, have you thought of using the "app" as the "category"? And if you need both an "app" and a "category", have you thought about putting both in the "app" field with say a dash in between? E.g. hr-applications, instead of having an app hr and a category application?
I am working on a display table version 1.2 on Struts 2 application. I am having problem with fetching value for "titleKey" in my diplay table column.
<display:column titleKey="title.key" >
I am kinda sure that I do not have configuration problem. I tried fetching the same value outside the table as :
<s:text name="title.key"/>
I am successful in doing that.
What could be the issue?
I don't know of any reason why DisplayTag would know about the S2 I18N mechanisms.
Either use DisplayTag's I18N support or by not using keys (e.g., the "title" attribute) and using values exposed by normal S2 mechanisms.