JAVA load already in database
Hello too all,
we've got a distributed system. SCS, CI running on Linux, db-instance on solaris with oracle.
We need to reinstall SCS and CI, because of a hardware change.
I've installed SCS and mounted /sapmnt/<SID>/global and /profiles folder on the db-host and started the database.
While reinstalling CI I get the following error:
The JAVA-Load in database <SID>/<host> has already been configured.
SOLUTION: Remove the schema and load it with a new load before you run this installation.
I could not reinstall the db-host, because I don't want to export the complete data in the database.
Are there any guides?
Regards Christian
What was the solution?
Do share.
Similar Messages
-
CRM 2007 The Java load in database SID/hostname has already been configured.
I had an CRM 2007 system on windows server 2008R2. I had an issue in CI system and reinstall it. But I got a problem when the java already configured in database. My database is very important so I can remove schema. I chose CRM2007>Oracle>ABAP+JAVA>HA system>Central Instance in the sapinst.
CJS-30109 The Java load in database GOL/crmdb has already been configured. SOLUTION: Remove the schema and load it with a new load before you run this installation.
ThanksHello Ashutosh ,
Thanks for your reply.
We have gone followed the below sequence:
SCS Installation
Database Instance Installation using backup/restore method
CI installation. -> getting error, when we provide the Java Components DVD.
Best Regards,
Anuj -
How to load a java script in oracle database
Is it possible to load d java script in Oracle database. while the object type is
java resource ..RENUJP wrote:
I meant to load a javascript to oracle database not to oracle appliocation.
like loadjava....
I can load a javascript to oracle database.. but i can't call it...Please re-read the comments above, especially the part about this not being a javascript nor oracle forum. Exactly what part about this information don't you understand? -
Dear Gurus,
We are facing the below issue when performing a homogeneous system copy of NW 7.0 system using backup/restore method for DB6 system.
The Java load in database <SID>/<hostname> has not been configured yet. You cannot run an installation from the System Copy folder with this load.
We went through the SAP Note http://service.sap.com/sap/support/notes/2049842, and followed the same but no luck.
We updated the Kernel to the latest, but still no luck.
Request for your quick help as we have to complete it by EOD today.
Thanks a lot in advance.
Best Regards,
AnujHello Ashutosh ,
Thanks for your reply.
We have gone followed the below sequence:
SCS Installation
Database Instance Installation using backup/restore method
CI installation. -> getting error, when we provide the Java Components DVD.
Best Regards,
Anuj -
Load java class into the database 10g
Hi ,
We have a program which creates pdf files by using bi publisher.for this program we r using some java package to create a directory in unix whenever invoiceprint program runs.
Now i need to load this class into database,so how can i load this class into database.
I got some samples and docs from google but i was confused with those wether i should load from Oracle/applmgr user.
So Could any one please tell me how can i load java class into oracle database.
I am verymuch thankful for your kind help.Its an emergency issue for me.
Thanks,
YMRHi,
http://www.oracle-training.cc/teas_elite_util9.htm
SS -
How can i load file into database from client-side to server-side
i want to upload file from client-side to server-side, i use the following code to load blob into database.
if the file is in the server-side, it can work, but if it in the client-side, it said that the system cannot find the file. i think it only will search the file is in the server-side or not, it will not search the client-side.
how can i solve it without upload the file to the server first, then load it into database??
try
ResultSet rset = null;
PreparedStatement pstmt =
conn.prepareStatement ("insert into docs values (? , EMPTY_BLOB())");
pstmt.setInt (1, docId);
pstmt.execute ();
// Open the destination blob:
pstmt.setInt (1, docId);
rset = pstmt.executeQuery (
"SELECT content FROM docs WHERE id = ? FOR UPDATE");
BLOB dest_lob = null;
if (rset.next()) {
dest_lob = ((OracleResultSet)rset).getBLOB (1);
// Declare a file handler for the input file
File binaryFile = new File (fileName);
FileInputStream istream = new FileInputStream (binaryFile);
// Create an OutputStram object to write the BLOB as a stream
OutputStream ostream = dest_lob.getBinaryOutputStream();
// Create a tempory buffer
byte[] buffer = new byte[1024];
int length = 0;
// Use the read() method to read the file to the byte
// array buffer, then use the write() method to write it to
// the BLOB.
while ((length = istream.read(buffer)) != -1)
ostream.write(buffer, 0, length);
pstmt.close();
// Close all streams and file handles:
istream.close();
ostream.flush();
ostream.close();
//dest_lob.close();
// Commit the transaction:
conn.commit();
conn.close();
} catch (SQLException e) {Hi,
Without some more details of the configuration, its difficult to know
what's happening here. For example, what do you mean by client side
and server side, and where are you running the upload Java application?
If you always run the application on the database server system, but can't
open the file on a different machine, then it sounds like a file protection
problem that isn't really connected with the database at all. That is to
say, if the new FileInputStream (binaryFile) statement fails, then its not
really a database problem, but a file protection issue. On the other hand,
I can't explain what's happening if you run the program on the same machine
as the document file (client machine), but you can't write the data to the
server, assuming the JDBC connection string is set correctly to connect to
the appropriate database server.
If you can provide some more information, we'll try to help.
Simon
null -
Calling a java loaded API from PL/SQL
HI,
I have a java program loaded in the Database.
For sake of clarity I am posting the java Program also.
package mypackage1;
public class WriteClob extends CLOB
public static void main(String[] args) {
Connection conn = null;
String url = null;
String user = null;
String password = null;
Properties props = new Properties();
String fileName = null;
String xml_test ="KINGSTON";
StringBuffer s_xml = new StringBuffer();
// PreparedStatement ps = null;
OraclePreparedStatement ps=null;
int ret_int=0;
props.put("user", "apps" );
props.put("password", "apps");
long len=0;
int temp;
ResultSet rs = null;
SimpleDateFormat fSDateFormat = null;
props.put("SetBigStringTryClob", "true");
long first=System.currentTimeMillis();
url = "jdbc:oracle:thin:@ap619sdb:4115:owf12dev";
user = "apps";
password = "apps";
try
DriverManager.registerDriver(new OracleDriver()); // Get the database connection
conn = DriverManager.getConnection( url, props );
long second=System.currentTimeMillis();
System.out.println("Time between conn. "+(second-first));
first=System.currentTimeMillis();
for (int i =0;i<1000;i++){
s_xml.append(xml_test);
second=System.currentTimeMillis();
System.out.println("Time between loop "+(second-first));
first=System.currentTimeMillis();
ps =(OraclePreparedStatement) conn.prepareStatement("insert into xml_clob_temp1 values(:1)");
ps.setString(1,s_xml.toString());
ps.executeUpdate();
second=System.currentTimeMillis();
System.out.println("Time between loop "+(second-first));
} catch(SQLException sqlexp){ sqlexp.printStackTrace(); }
Now i am trying to create a procedure to call this Java API.
create or replace package load_perf as
procedure WriteClob ;
end;
create or replace package body load_perf as
procedure WriteClob
is
language java name 'mypackage1.WriteClob.main(java.lang.String)';
end;
I have tried debugging this a lot and am not able to overcome this error while creating the procedure.
LINE/COL ERROR
3/1 PL/SQL: Item ignored
5/15 PLS-00311: the declaration of
"mypackage1.WriteClob.main(java.lang.String)" is incomplete or
malformed
I have earlier created Java APIs which have returned some value and have been able to load them in the DB and call through a PL/SQL function wrapper.
But I am unable to create a procedure for this.
I have tried all sorts of debugging but always am getting error around this.
Can someone Please take a look at this Pronblem.
Thanks In Advance,
GauravA proper designed application in the database tier is far more scalable and performs better than using a separate middle tier for the application.
This should be self evident.
A middle tier requires more moving parts between the application and data. There now sits a network pipe between application and data. There are more software layers that slows down the interaction of the application with the data - more stuff that can go wrong. More stuff that needs to be maintained and configured and secured.
What's more, the database tier is a lot more scalable than the middle tier. Oracle Real Application Clusters. Oracle Parallel Processing. Oracle Shared Server. Etc.
These are robust and mature technologies.
One major fact that seems to be missed by so-called IS architects favouring a middle tier is that the middle tier cannot make a single database query or transaction go faster.
Scaling the middle tier is done by throwing more hardware at it. But not a single additional mid-tier h/w platform will make the database tier any faster. Will make the database tier scale.
Then there is also the issue of costs. A middle tier requires additional hardware. It requires support and maintenance agreements with the vendors. It requires middle tier software to be purchased. It requires a new set of skills to do middle tier development. It deals with different technology and different programming languages.
Why? How can this approach be sensible when:
- Oracle scales exceedingly well (and this scalability is not dependent on more h/w purchasing)
- Oracle deals with a single programming language (PL/SQL)
- Oracle supports high availability
- Oracle supports redudancy
- Oracle supports the complete application tier inside the database
If you have problems now leveraging Oracle (as an application tier), then you will have more problems when doing it a middle layer. Why?
Because the lack of experience/skill/knowledge required to make Oracle work for you, is not now suddenly negated and not needed when moving the application tier to Java. -
Issue to load data from database to XML file. error: ODI-40768
Hi,
While I am trying to load data from database to XML following error is appearing.
ODI-1228: Task TEST_XML_DATA (Integration) fails on the target XML connection MyLOCALXSD.
Caused By: java.sql.SQLException: ODI-40768: Could not save the file <default>:C:\DATA_FILE\www.xml because a class java.io.IOException occurred and said: The filename, directory name, or volume label syntax is incorrect
at com.sunopsis.jdbc.driver.xml.SnpsXmlFile.writeToFile(SnpsXmlFile.java:751)
at com.sunopsis.jdbc.driver.xml.SnpsXmlConnection.internalExecute(SnpsXmlConnection.java:769)
at com.sunopsis.jdbc.driver.xml.SnpsXmlPreparedStatement.execute(SnpsXmlPreparedStatement.java:46)
at oracle.odi.runtime.agent.execution.sql.SQLCommand.execute(SQLCommand.java:166)
at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:102)
at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:1)
at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2906)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2609)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:540)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:453)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1740)
at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$2.doAction(StartSessRequestProcessor.java:338)
at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:214)
at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:272)
at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$0(StartSessRequestProcessor.java:263)
at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$StartSessTask.doExecute(StartSessRequestProcessor.java:822)
at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:123)
at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:83)
at java.lang.Thread.run(Thread.java:662)
jdbc url: jdbc:snps:xml?d=C:\test_xsd.xsd&s=TESTSQL&re=employeesX&ro=true
physical schema: TESTSQL
Knowledge modules are:
LKM: LKM SQL to SQL
IKM: IKM XML Control Append
CKM: CKM SQL
Parameters set are:
CREATE_XML_FILE: true
XML_PATH:<default>:C:\DATA_FILE\www.xml
I have tried to change the directory path but error is still there.
Could some one please help me to resolve the issue?
Regards,
user1672911Hi,
The trouble in "<default>:" - if you set XML_PATH as C:\DATA_FILE\www.xml instead <default>:C:\DATA_FILE\www.xml- it will work correctly.
Greetings,
Eugene -
Java: Loading Resource Bundle File with UTF-8
I have found out all my previous problems now, thank you all for your assitance with this...
During the time we have worked so solve our problem with UTF-8 charset we have found new problem with this?
I don't know if this is the right forum to put this up, if not please let us know where to go with this?
I have prepared both Eclipse (JSP Files) and GlassFish to run all my files in charset UTF-8. Then i got my
resource bundle files(property files) to use UTF-8 encoding. Everything looks fine in my text editor. Then
when i upload these pages every character retrieved from my resource bundles look garbled. This is because
Java loads property files using ISO 8859-1 character encoding.
This is a problem from Sun i have read on the internet!
Note: that in JDK 1.6, you can use PropertyResourceBundle constructor to take a Reader which uses UTF-8 encoding.
please have a look at these links for more info:
[http://www.kai-mai.com/node/128]
[http://java.sun.com/javase/6/docs/api/java/util/PropertyResourceBundle.html]
Note: PropertyResourceBundle can be constructed either from an InputStream or a Reader, which represents a property file.
Constructing a PropertyResourceBundle instance from an InputStream requires that the input stream be encoded in ISO-8859-1.
In that case, characters that cannot be represented in ISO-8859-1 encoding must be represented by Unicode Escapes,
whereas the other constructor which takes a Reader does not have that limitation.
What i have read and understand is that the real solution to the problem is: Get the fmt lib to use a Reader instead of an
InputStream. Alternativly if it works get a ResourceBundle instead of creating one that is wrong all the time? I have to create
my own ResourceBundle instead of using my own fmt lib wich i cannot trust in a way any more. Is this right or am i comletly wrong?
My WebTexts files, en, sv and ry are my resource property bundles. To be able to read them i will use resource property bundle reader.
Fmt lib gives me this but it seems that it inciates this in an InputStream (wich is looked to iso-8859-1) instead of a reader who can
read UTF-8 without no problem. So can i get my fmt lib to change this or not, anybody have an idea about this???Torleif wrote:
Ok, i know there are a few ways of doing this already. The problem is that i have no idea how to use these different problem solving issues. First we have the;
1. native2ascii command line utility.
2. use the XML properties format.
3. other ways of converting from iso-8859-1 to utf-8.
The last one i have tried already but i never get this to work. So after knowing of 2 standardized solutions you choose to implement your own non-standard soltion? That's usually not a good idea until you've verified that the standardized solution don't help.
This is also not the best solution to the problem i have to say. This way i will have both properties files and source files to work with and that is to much i think. Either i will use the native2ascii command or use XML properties format like you say here. I need some more insight in how these two work only because i have no idea my self.Uhm .. read [the documentation|http://java.sun.com/javase/6/docs/api/java/util/Properties.html]? loadFromXML/storeToXML work pretty much exactly the same as load/store, except they handle XML. Try it, look at what it produces, learn.
Could you please help and explain how to use either this native2ascii command line work or how this XML format properties would work for me. Please i need guidance here with this!!![native2ascii is documented as well|http://java.sun.com/javase/6/docs/technotes/tools/windows/native2ascii.html].
If you have a specific question after reading those, feel free to ask here.
You really have to work on your Google-fu, it seems to be too weak. -
Required the details of jar files which is loaded in the database
Hi
We are having a 10g database which is running under Solaris machine. There are lot of .jar files which are loaded into the database. I would like to know how to find those .jar file details atlease the name of the files which are loaded in the database. Is there any view for this.
I couldnt find anything from the Java option in TOAD
Please provide a solution.
Thanks
SHIYAS MFrom 11g onwards, you have
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> desc javajar$
Name Null? Type
NAME NOT NULL VARCHAR2(30)
OWNER# NOT NULL NUMBER
PATH VARCHAR2(4000)
CONTENTS BLOB
SQL> desc javajarobjects$
Name Null? Type
JARNAME NOT NULL VARCHAR2(30)
OWNER# NOT NULL NUMBER
OBJNAME NOT NULL VARCHAR2(40)
NAMESPACE NOT NULL NUMBER -
JAVA execution consumed significant database time
Dear all,
DB 11. on solaris..
I have a time consuming package.. this package unloads data in the current db and loads data from another remote db in the same network. below is the recommendation from Oracle ADDM report.
This session is a work flow session. What can I do for JAVA execution consumed significant database time.?
JAVA execution consumed significant database time.
Recommendation 1: SQL Tuning
Estimated benefit is .5 active sessions, 43.98% of total activity.
Action
Tune the PL/SQL block with SQL_ID "6bd4fvsx8n42v". Refer to the "Tuning
PL/SQL Applications" chapter of Oracle's "PL/SQL User's Guide and
Reference".
Related Object
SQL statement with SQL_ID 6bd4fvsx8n42v.
DECLARE job BINARY_INTEGER := :job; next_date DATE := :mydate;
broken BOOLEAN := FALSE; BEGIN OWF_USER.START_METS_REFRESH(SYSDATE );
:mydate := next_date; IF broken THEN :b := 1; ELSE :b := 0; END IF;
END;Please advise
KaiHi Forstmann,
Thanks for your update.
Even i have collected ADDM report, extract of Node1 report as below
FINDING 1: 40% impact (22193 seconds)
Cluster multi-block requests were consuming significant database time.
RECOMMENDATION 1: SQL Tuning, 6% benefit (3313 seconds)
ACTION: Run SQL Tuning Advisor on the SQL statement with SQL_ID
"59qd3x0jg40h1". Look for an alternative plan that does not use
object scans.
SYMPTOMS THAT LED TO THE FINDING:
SYMPTOM: Inter-instance messaging was consuming significant database
time on this instance. (55% impact [30269 seconds])
SYMPTOM: Wait class "Cluster" was consuming significant database
time. (55% impact [30271 seconds])
FINDING 3: 13% impact (7008 seconds)
Read and write contention on database blocks was consuming significant
database time.
NO RECOMMENDATIONS AVAILABLE
SYMPTOMS THAT LED TO THE FINDING:
SYMPTOM: Inter-instance messaging was consuming significant database
time on this instance. (55% impact [30269 seconds])
SYMPTOM: Wait class "Cluster" was consuming significant database
time. (55% impact [30271 seconds])
Any help from your side , please?
Thanks,
Sunand -
Oracle 10.1, Whats the best way to load XML in database?
Hi All,
I am a typical Oracle developer. I know some Java and some XML technologies, but not an expert.
I will be receiving XML files from some system, which will be,
- of reasonable size like 2 to 15 MBs
- of reasonable complexity, like the root element have children, grand-children and great-grand-children, with attributes and all
- Every day it needs to be loaded to Oracle database, in relational format
- we need not update the XML data, only put the XML data in relational table
My questions are,
- With Oracle 10.1, XML DB, what is the best way to load this XML file to relational Oracle tables ?
- What can be the steps in this process ?
- In the documentation, I was lost and was not able to decide anything concrete
- If I write a pure Java program with SAX API and load the data to Oracle database in same program, is it a good idea?
- Is there any pure Oracle based way to do this?
- If I want to avoid using DOM parser, as it will need more JAVA_POOL_SIZE, what can be the way ?
Please help.
ThanksMany customer solve this problem by registering an XML Schema that corresponds to their XML and then creating relational views over the XML that allow them to access the content in a relational manner. They then use insert as select operations on the relational views to transfer data from the XML into relational tables where necessary. There are a large number of threads in this forum with detailed examples of how this can be done. Most of the customers who have adopted this approach have discovered that this is the least complex approach in terms of code that to be developed / maintained and offeres acceptable performance.
-
How to call procedure in Java from SQL Server Database
Hello Every Body
i Have Question about
How to call procedure in Java from SQL Server Database
ThanksHi,
have you tried a Google search? I just gave it a 3 second try and already found: http://stackoverflow.com/questions/6113674/how-do-i-execute-a-ms-sql-server-stored-procedure-in-java-jsp-returning-table-d
Frank -
How to generate the java classes of the database tables
Hi,
I am using Sun One 4 update1 CE for generate java classes of tables from an Oracle database. I have got the database schema file. However, when I right clicked on the database schema file, there is no selection for "Generate Java...".
Besides, when I was trying to use database Schema template from the project tab in the explore window by double click on the project, after following all the procedures of inputing the database url, driver, uername, password, and select the table to generate, the following exception came out:
Tue Jan 28 16:22:28 PST 2003: java.lang.NullPointerException: Posted StackTrace
Annotation: Exception occurred in Request Processor
org.openide.util.RequestProcessor$Holder: Posted StackTrace(task org.netbeans.core.ModuleActions$1@e4b7d3 [-31035, 1, -1])
at org.openide.util.RequestProcessor$Holder.fillInStackTrace(RequestProcessor.java:300)
at java.lang.Throwable.<init>(Throwable.java:195)
at java.lang.Exception.<init>(Exception.java:41)
at org.openide.util.RequestProcessor$Holder.<init>(RequestProcessor.java:280)
at org.openide.util.RequestProcessor$Task.createHolder(RequestProcessor.java:333)
at org.openide.util.RequestProcessor.post(RequestProcessor.java:100)
at org.openide.util.RequestProcessor.post(RequestProcessor.java:73)
at org.netbeans.core.ModuleActions.invokeAction(ModuleActions.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.openide.explorer.view.TreeView.invokeAction(TreeView.java:878)
at org.openide.explorer.view.TreeView$PopupSupport.mouseClicked(TreeView.java:958)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:208)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:207)
at java.awt.Component.processMouseEvent(Component.java:5096)
at java.awt.Component.processEvent(Component.java:4890)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3598)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3439)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3174)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1585)
at java.awt.Component.dispatchEvent(Component.java:3439)
[catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
Tue Jan 28 16:22:28 PST 2003: java.lang.NullPointerException: <no message>
java.lang.NullPointerException
at org.netbeans.modules.projects.ProjectDataObject.add(ProjectDataObject.java:204)
at org.netbeans.modules.projects.AddNewAction.performAction(AddNewAction.java:88)
at org.openide.util.actions.NodeAction.actionPerformed(NodeAction.java:167)
at org.netbeans.core.ModuleActions$1.run(ModuleActions.java:105)
at org.openide.util.Task.run(Task.java:152)
[catch] at org.openide.util.RequestProcessor$ProcessorThread.run(RequestProcessor.java:622)
Any suggestions to the solution of these problems are greatly appreciated. Thanks.
Yi-Xiongyou also could use this to generate java beans out of database tables:
* Convert SQL type code to corresponding Java class.
* @param sqlType One of java.sql.Types.xxx.
* @return Class that corresponds to the given type.
public static Class toClass(int sqlType) {
Class result = null;
switch (sqlType) {
case Types.BIGINT :
case Types.INTEGER :
case Types.SMALLINT :
case Types.TINYINT :
result = Integer.class;
break;
case Types.BIT :
case Types.BOOLEAN :
result = Boolean.class;
break;
case Types.CHAR :
result = Character.class;
break;
case Types.DATE :
case Types.TIMESTAMP :
result = java.util.Date.class;
break;
case Types.DECIMAL :
case Types.DOUBLE :
case Types.FLOAT :
result = BigDecimal.class;
break;
case Types.NULL :
result = null;
break;
case Types.LONGVARCHAR :
case Types.VARCHAR :
default :
result = String.class;
break;
return result;
}//toClass()
* Create a Java bean (source file) to map a database table. The class name is the table name, the bean
* properties are the table columns. Each column will result in a property with a corresponding set() and
* get() method.
* @param connection Database connection to load table from.
* @param tableName Name of table to create the bean for.
* @param packageName Name of package for Java class.
* @param className Name of Java class to create.
* @param superClass Optional name of super class.
* @return Java source of container class.
* @throws SQLException, IOException
* @see <a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html">Data Access Object </a>
public static String getTableBean(Connection connection, String tableName, String packageName, String className, String superClass)
throws SQLException, IOException {
String result = null;
if (connection != null && tableName != null) {
//read table columns:
DatabaseMetaData dmd = connection.getMetaData();
ResultSet resultSet = dmd.getColumns(null, "%", tableName, null);
Properties props = new Properties();
if (resultSet != null) {
while (resultSet.next()) { //for each table
String name = resultSet.getString("COLUMN_NAME");
int type = resultSet.getInt("DATA_TYPE");
props.setProperty(name, ""+type);
}//next table
}//else: resultSet unavailable
Set imports = new HashSet();
StringBuffer sb1 = new StringBuffer(); //fields
StringBuffer sb2 = new StringBuffer(); //methods
StringBuffer sb3 = new StringBuffer(); //toString()
Enumeration enum = props.keys();
while (enum.hasMoreElements()) {
String columnName = (String) enum.nextElement();
//change first character of column name to lower case:
String fieldName = columnName.substring(0, 1).toLowerCase() + columnName.substring(1);
//datat type:
String stype = props.getProperty(columnName, ""+Types.VARCHAR);
int type = (new Integer(stype)).intValue();
Class javaClass = toClass(type);
String typeName = "String"; //default
if (javaClass != null) {
String javaClassName = javaClass.getName();
int lastDot = javaClassName.lastIndexOf('.');
if (lastDot >= 0) {
typeName = javaClassName.substring(lastDot + 1);
if (!javaClassName.startsWith("java.lang.")) {
imports.add(javaClassName);
//field:
sb1.append(" /** ");
sb1.append(columnName);
sb1.append(" */\n");
sb1.append(" private ");
sb1.append(typeName);
sb1.append(" ");
sb1.append(fieldName);
sb1.append(" = null;\n");
//toString() method:
sb3.append(" sb.append(\",");
sb3.append(fieldName);
sb3.append("=\");\n");
sb3.append(" sb.append(");
sb3.append(fieldName);
sb3.append(");\n");
//set method:
sb2.append(" /**\n");
sb2.append(" * Set ");
sb2.append(columnName);
sb2.append(".\n *\n * @param value ");
sb2.append(columnName);
sb2.append(" to set.\n");
sb2.append(" */\n");
sb2.append(" public void set");
sb2.append(columnName);
sb2.append("(");
sb2.append(typeName);
sb2.append(" value) {\n ");
sb2.append(fieldName);
sb2.append(" = value;\n }\n\n");
//get method:
sb2.append(" /**\n");
sb2.append(" * Get ");
sb2.append(columnName);
sb2.append(".\n *\n * @return ");
sb2.append(columnName);
sb2.append(".\n */\n");
sb2.append(" public ");
sb2.append(typeName);
sb2.append(" get");
sb2.append(columnName);
sb2.append("() {\n");
sb2.append(" return ");
sb2.append(fieldName);
sb2.append(";\n }\n\n");
}//next column
//build class source code:
StringBuffer sb = new StringBuffer();
sb.append("/* $Header: /data/iComps/icf/prg/java/src/de/icomps/sql/JDBCUtils.java 9 24.10.03 14:25 Hilpert $ */\n");
sb.append("package ");
sb.append(packageName);
sb.append(";\n\n");
//import statements:
Iterator iterator = imports.iterator();
while (iterator.hasNext()) {
String jcn = (String) iterator.next();
sb.append("import ");
sb.append(jcn);
sb.append(";\n");
if (imports.size() > 0) {
sb.append("\n");
//class:
sb.append("/**\n");
sb.append(" * Container class to store data of one record (row) of table '"+tableName+"'.\n");
sb.append(" *\n");
sb.append(" * @version $Revision: 9 $ ($Date: 24.10.03 14:25 $)\n");
sb.append(" * @author $Author: Hilpert $\n");
sb.append(" */\n");
sb.append("public class ");
sb.append(className);
if (superClass != null) {
sb.append(" extends ");
sb.append(superClass);
sb.append(" {\n\n");
//fields:
sb.append(sb1.toString());
//methods:
sb.append("\n\n");
sb.append(sb2.toString()); //methods
//overwrite toString() method:
sb.append(" /**\n");
sb.append(" * Overwrite super.\n");
sb.append(" *\n * @return String representation of the object.\n");
sb.append(" */\n");
sb.append(" public String toString() {\n");
sb.append(" StringBuffer sb = new StringBuffer(super.toString());\n\n");
sb.append(sb3.toString());
sb.append("\n return sb.toString();\n");
sb.append(" }\n\n");
sb.append("}//"+className);
result = sb.toString();
}//else: input unavailable
return result;
}//getTableBean() -
How do I add text typed in a Java GUI to my database?
Using NetBeans, I've created a GUI, which has a 5 text boxes and an add/sumbit button. I've also created a database, which is on my Runtime Panel in Netbeans, and has a table with 5 columns. Once my GUI is running, I want the Add button to insert the information from each of the text boxes to the 5 columns in a row of the database. I haven't added any Event-> Action to my Add button yet.
I tried learning how to do this through the netbeans GUI JDBC tutorial, but it only showed a particular example, and didn't explain how this could be done in a differing situation. Can someone please tell me the code I'd need to access the database from the source code of my GUI?
thanksNote that learning java and JDBC (and databases) at the same time is not a good idea.
Basically you do this.
1. Extract the values from the gui as strings
2. Open a JDBC connection.
3. Create a SQL insert statement.
4. Create a java string using 3.
5. Create a prepared statement using 4 (modifying the string appropriately)
6. Call executeUpdate (or whatever the JDBC method is called.)
7. Appropriately close the statement and connection.
8. Handle error conditions with appropriate try/catches for all of the above.
Maybe you are looking for
-
Say, I got an error using the BEA XML bean method removeMetric(i) as follows: Note: in my schema metric is a complex type within each other type. Metrics Filter failed: com.bea.xbean.values.XmlValueDisconnectedException Can you tell me where to find
-
I own a Soyo HD ready LCD, and want to use it as my second monitor, wife will not let me purchase the 30 HD Cinema, which I use with Aperture. This LCD has both DVI, and VGA. I prefer to use DVI, but seem to not be able to config correctly. Any ideas
-
Scrolling background will not stop
I am trying to make a horzontial flash scrolling background and I cant seem to get it to stop at the last frame. animator=createEmptyMovieClip('animator',1); bg_1=animator.attachMovie('bg_mc','bg_1',1); bg_2=animator.attachMovie('bg_mc','bg_2',1); bg
-
Belkin Auto Kit Compatible with iPhone?
I've been reading here that the output voltage for the firewire iPod chargers are different from what the iPhone needs, and may damage it. So now I'm wondering if the Belkin Auto Kit outputs something that's too high too. Does anyone know the answer?
-
Error in approving Request at Stage Security.
HI All, error in approving request at stage security.Tried to paste system log but SDN site is not allowing to send the thread with the system log. I can send the brief error description,help me out from this error. application=XYZ,shortDesc=xyzzz,ke