Revision 2355
Added by sgarg almost 20 years ago
src/upgrade_db_to_1_5.java | ||
---|---|---|
32 | 32 |
public class upgrade_db_to_1_5{ |
33 | 33 |
public static void main(String [] ags) throws IOException{ |
34 | 34 |
Connection sqlca = null; |
35 |
Statement sqlStatement, sqlStatement2 = null; |
|
35 |
Statement sqlStatement = null; |
|
36 |
PreparedStatement pstmt = null; |
|
36 | 37 |
ResultSet rset = null; |
38 |
String database = "@database@"; |
|
39 |
String url = "@jdbc-connect@"; |
|
40 |
String user = "@user@"; |
|
41 |
String password = "@password@"; |
|
42 |
|
|
37 | 43 |
try{ |
38 |
|
|
39 | 44 |
// Create a JDBC connection to the database |
40 | 45 |
DriverManager.registerDriver(new @dbDriver@()); |
41 |
sqlca= DriverManager.getConnection ("@jdbc-connect@", "@user@", "@password@");
|
|
46 |
sqlca= DriverManager.getConnection (url, user, password);
|
|
42 | 47 |
|
43 | 48 |
// Delete old nodedatanumerical column from xml_nodes if one exsists |
44 | 49 |
try { |
45 |
System.out.print( |
|
50 |
System.out.println(
|
|
46 | 51 |
"Deleting old nodedatanumerical column from xml_nodes..."); |
47 | 52 |
|
48 |
sqlStatement = sqlca.createStatement();
|
|
49 |
sqlStatement.executeQuery(
|
|
50 |
"ALTER TABLE xml_nodes DROP COLUMN nodedatanumerical");
|
|
51 |
sqlStatement.close();
|
|
53 |
pstmt = sqlca.prepareStatement(
|
|
54 |
"ALTER TABLE xml_nodes DROP COLUMN nodedatanumerical");
|
|
55 |
pstmt.execute();
|
|
56 |
pstmt.close();
|
|
52 | 57 |
|
53 |
System.out.println(" done.");
|
|
58 |
System.out.println("Done.");
|
|
54 | 59 |
} |
55 | 60 |
catch (Exception e) { |
61 |
e.printStackTrace(); |
|
56 | 62 |
System.out.println(" column not found."); |
57 | 63 |
} |
58 | 64 |
|
59 | 65 |
// Create nodedatanumerical column in xml_nodes |
60 |
System.out.print( |
|
66 |
System.out.println(
|
|
61 | 67 |
"Creating new nodedatanumerical column in xml_nodes..."); |
62 | 68 |
|
63 |
sqlStatement = sqlca.createStatement(); |
|
64 |
sqlStatement.executeQuery( |
|
65 |
"ALTER TABLE xml_nodes ADD nodedatanumerical number"); |
|
66 |
sqlStatement.close(); |
|
69 |
if(database.equals("oracle")){ |
|
70 |
pstmt =sqlca.prepareStatement( |
|
71 |
"ALTER TABLE xml_nodes ADD nodedatanumerical NUMBER"); |
|
72 |
} else { |
|
73 |
pstmt =sqlca.prepareStatement( |
|
74 |
"ALTER TABLE xml_nodes ADD nodedatanumerical FLOAT8"); |
|
75 |
} |
|
76 |
pstmt.execute(); |
|
77 |
pstmt.close(); |
|
67 | 78 |
|
68 |
System.out.println(" done.");
|
|
79 |
System.out.println("Done.");
|
|
69 | 80 |
|
70 | 81 |
// Copy numerical values from nodedata to |
71 | 82 |
// nodedatanumerical column in xml_nodes |
72 |
System.out.print( |
|
83 |
System.out.println(
|
|
73 | 84 |
"Copy numerical values from nodedata to nodedatanumerical " |
74 | 85 |
+ "in xml_nodes..."); |
75 | 86 |
|
... | ... | |
90 | 101 |
if(!nodedata.trim().equals("")){ |
91 | 102 |
double s = Double.parseDouble(nodedata); |
92 | 103 |
|
93 |
sqlStatement2 = sqlca.createStatement(); |
|
94 |
sqlStatement2.executeQuery( |
|
104 |
pstmt =sqlca.prepareStatement( |
|
95 | 105 |
"update xml_nodes set nodedatanumerical = " + s + |
96 | 106 |
" where nodeid=" + nodeid); |
97 |
sqlStatement2.close(); |
|
107 |
pstmt.execute(); |
|
108 |
pstmt.close(); |
|
98 | 109 |
|
99 | 110 |
count++; |
100 | 111 |
} |
... | ... | |
104 | 115 |
System.out.println("Exception:" + e.getMessage()); |
105 | 116 |
} |
106 | 117 |
} |
107 |
System.out.println(" done. " + count + " values copied.");
|
|
118 |
System.out.println("Done. " + count + " values copied.");
|
|
108 | 119 |
|
109 | 120 |
rset.close(); |
110 | 121 |
sqlStatement.close(); |
Also available in: Unified diff
Modified code to work with Postgresql also.